Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][account_invoice_constraint_chronology] better error message #2035

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use translation function arguments instead of format()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the translation functions be automatically validated with precommit? I thought that if the precommit was passing, it was because it was a valid format (in my personal experience, I get an error if I don't use the translation function).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this is new from >= v16. So, maybe you can propose a change in pylint-odoo.

Comment on lines +41 to +44
Copy link
Member

@sbidoul sbidoul Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Chronology conflict: A conflicting draft invoice {name} for "
"{partner} dated before {date_invoice} exists, please validate it "
"first or remove its invoice date."
).format(
"Chronology conflict: A conflicting draft invoice %(name)s for "
"%(partner)s dated before %(date_invoice)s exists, please validate it "
"first or remove its invoice date."

@rvalyi would you this before merging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try to find the time, carnival here :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enjoy!

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