Skip to content

Commit

Permalink
[IMP] account_invoice_constraint_chronology: better message
Browse files Browse the repository at this point in the history
The error message in case of an older conflicting invoice was not really
helpful. Now it will show the conflicting invoice name if any and also
the customer name (because a draft invoice will likely be named '/' so
just the name might not be enough). This will help the user to find
the offending invoice. It also suggest to removed the invoice date
as a possible work around.
  • Loading branch information
rvalyi committed Feb 24, 2025
1 parent 44b8ce7 commit 2969978
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions account_invoice_constraint_chronology/model/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ def _get_older_conflicting_invoices_domain(self):
]
)

def _raise_older_conflicting_invoices(self):
def _raise_older_conflicting_invoices(self, older_move):
self.ensure_one()
raise UserError(
_(
"Chronology conflict: A conflicting draft invoice dated before "
"{date_invoice} exists, please validate it first."
).format(date_invoice=format_date(self.env, self.invoice_date))
"Chronology conflict: A conflicting draft invoice {name} for "
"{partner} dated before {date_invoice} exists, please validate it "
"first or remove its invoice date."
).format(
date_invoice=format_date(self.env, self.invoice_date),
name=older_move.name,
partner=older_move.partner_id.name,
)
)

def _get_newer_conflicting_invoices_domain(self):
Expand Down Expand Up @@ -174,8 +179,11 @@ def write(self, vals):
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()
older_move = self.search(
move._get_older_conflicting_invoices_domain(), limit=1
)
if older_move:
move._raise_older_conflicting_invoices(older_move)
if move in previously_validated:
if self.search(
move._get_sequence_order_conflicting_previously_validated(), limit=1
Expand Down

0 comments on commit 2969978

Please sign in to comment.