diff --git a/account_invoice_constraint_chronology/model/account_move.py b/account_invoice_constraint_chronology/model/account_move.py index 56135830..c95dfdcb 100644 --- a/account_invoice_constraint_chronology/model/account_move.py +++ b/account_invoice_constraint_chronology/model/account_move.py @@ -94,7 +94,7 @@ class AccountMove(models.Model): def write(self, vals): if vals.get("state") != "posted": return super().write(vals) - + previously_validated = self.filtered(lambda m: m.name and m.name != "/") newly_posted = self.filtered(lambda move: move.state != "posted") res = super().write(vals) for move in newly_posted & self.filtered("journal_id.check_chronology"): @@ -104,6 +104,8 @@ class AccountMove(models.Model): move._raise_sequence_ordering_conflict() if self.search(move._get_older_conflicting_invoices_domain(), limit=1): move._raise_older_conflicting_invoices() + if move in previously_validated: + continue if self.search(move._get_newer_conflicting_invoices_domain(), limit=1): move._raise_newer_conflicting_invoices() diff --git a/account_invoice_constraint_chronology/tests/test_account_invoice_constraint_chronology.py b/account_invoice_constraint_chronology/tests/test_account_invoice_constraint_chronology.py index 499355c1..024c1a65 100644 --- a/account_invoice_constraint_chronology/tests/test_account_invoice_constraint_chronology.py +++ b/account_invoice_constraint_chronology/tests/test_account_invoice_constraint_chronology.py @@ -133,3 +133,19 @@ class TestAccountInvoiceConstraintChronology(common.SavepointCase): self.invoice_1.invoice_date = self.tomorrow with self.assertRaisesRegex(UserError, "higher number"): self.invoice_1.action_post() + + def test_modify_validated_past_invoice(self): + """We've got an invoice from yesterday that we need to modify but new ones + have been posted since. As the invoice already has a name, we should be able + to validate it""" + self.invoice_1.invoice_date = self.yesterday + self.invoice_1.action_post() + self.invoice_2.invoice_date = self.today + self.invoice_2.action_post() + self.invoice_1.button_cancel() + self.invoice_1.button_draft() + self.invoice_1.action_post() + self.invoice_1_5 = self.invoice_1.copy() + self.invoice_1_5.invoice_date = self.yesterday + with self.assertRaises(UserError): + self.invoice_1_5.action_post()