2
0
This commit is contained in:
Alexey Pelykh 2021-04-08 07:41:03 +02:00 committed by Zina Rasoamanana
parent 3ac663af91
commit b8f8b91687
4 changed files with 86 additions and 10 deletions

View File

@ -4,9 +4,9 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -14,26 +14,44 @@ msgstr ""
"Plural-Forms: \n"
#. module: account_invoice_constraint_chronology
#: model:ir.model.fields,field_description:account_invoice_constraint_chronology.field_account_bank_statement_import_journal_creation__check_chronology
#: model:ir.model.fields,field_description:account_invoice_constraint_chronology.field_account_journal__check_chronology
msgid "Check Chronology"
msgstr ""
#. module: account_invoice_constraint_chronology
#: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:66
#: code:addons/account_invoice_constraint_chronology/model/account_move.py:0
#, python-format
msgid "Chronology Error. Please confirm older draft invoices before {date_invoice} and try again."
msgid ""
"Chronology conflict: A conflicting draft invoice dated before {date_invoice}"
" exists, please validate it first."
msgstr ""
#. module: account_invoice_constraint_chronology
#: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:82
#: code:addons/account_invoice_constraint_chronology/model/account_move.py:0
#, python-format
msgid "Chronology Error. There exist at least one invoice with a later date to {date_invoice}."
msgid ""
"Chronology conflict: A conflicting validated invoice dated after "
"{date_invoice} exists."
msgstr ""
#. module: account_invoice_constraint_chronology
#: model:ir.model,name:account_invoice_constraint_chronology.model_account_invoice
msgid "Invoice"
#: code:addons/account_invoice_constraint_chronology/model/account_move.py:0
#, python-format
msgid ""
"Chronology conflict: An invoice with a higher number {highest_name} dated "
"before {date_invoice} exists."
msgstr ""
#. module: account_invoice_constraint_chronology
#: model:ir.model.fields,field_description:account_invoice_constraint_chronology.field_account_journal__display_name
#: model:ir.model.fields,field_description:account_invoice_constraint_chronology.field_account_move__display_name
msgid "Display Name"
msgstr ""
#. module: account_invoice_constraint_chronology
#: model:ir.model.fields,field_description:account_invoice_constraint_chronology.field_account_journal__id
#: model:ir.model.fields,field_description:account_invoice_constraint_chronology.field_account_move__id
msgid "ID"
msgstr ""
#. module: account_invoice_constraint_chronology
@ -41,3 +59,13 @@ msgstr ""
msgid "Journal"
msgstr ""
#. module: account_invoice_constraint_chronology
#: model:ir.model,name:account_invoice_constraint_chronology.model_account_move
msgid "Journal Entry"
msgstr ""
#. module: account_invoice_constraint_chronology
#: model:ir.model.fields,field_description:account_invoice_constraint_chronology.field_account_journal____last_update
#: model:ir.model.fields,field_description:account_invoice_constraint_chronology.field_account_move____last_update
msgid "Last Modified on"
msgstr ""

View File

@ -61,6 +61,36 @@ class AccountMove(models.Model):
).format(date_invoice=format_date(self.env, self.invoice_date))
)
def _get_sequence_order_conflicting_invoices_domain(self):
self.ensure_one()
if not self.name or self.name == "/":
return expression.FALSE_DOMAIN
last_sequence = self._get_last_sequence()
if not last_sequence or self.name > last_sequence:
return expression.FALSE_DOMAIN
return expression.AND(
[
[("name", "=", last_sequence)],
self._get_conflicting_invoices_domain(),
[("state", "=", "posted"), ("invoice_date", "<", self.invoice_date)],
]
)
def _raise_sequence_ordering_conflict(self):
self.ensure_one()
raise UserError(
_(
"Chronology conflict: An invoice with a higher number {highest_name}"
" dated before {date_invoice} exists."
).format(
highest_name=self._get_last_sequence(),
date_invoice=format_date(self.env, self.invoice_date),
)
)
def write(self, vals):
if vals.get("state") != "posted":
return super().write(vals)
@ -68,6 +98,10 @@ class AccountMove(models.Model):
newly_posted = self.filtered(lambda move: move.state != "posted")
res = super().write(vals)
for move in newly_posted & self.filtered("journal_id.check_chronology"):
if self.search(
move._get_sequence_order_conflicting_invoices_domain(), limit=1
):
move._raise_sequence_ordering_conflict()
if self.search(move._get_older_conflicting_invoices_domain(), limit=1):
move._raise_older_conflicting_invoices()
if self.search(move._get_newer_conflicting_invoices_domain(), limit=1):

View File

@ -4,3 +4,4 @@ It prevents the validation of invoices when:
* there are draft invoices with a prior date
* there are validated invoices with a later date
* there are validated invoices with a higher number

View File

@ -120,3 +120,16 @@ class TestAccountInvoiceConstraintChronology(common.SavepointCase):
refund = self.AccountMove.browse(refund["res_id"])
with self.assertRaises(UserError):
refund.action_post()
def test_invoice_higher_number(self):
self.invoice_1.invoice_date = self.yesterday
self.invoice_1.action_post()
self.invoice_1.button_draft()
self.invoice_1.invoice_date = False
self.invoice_2.invoice_date = self.today
self.invoice_2.action_post()
self.invoice_1.invoice_date = self.tomorrow
with self.assertRaisesRegex(UserError, "higher number"):
self.invoice_1.action_post()