From 5b35915d6c59e90658cd4e5ccd3fcb4bd6e8d49b Mon Sep 17 00:00:00 2001 From: "Antoine Dupuis (andu)" <andu@odoo.com> Date: Fri, 19 May 2023 14:28:59 +0000 Subject: [PATCH] [REF] account: Vendor Bills: Refactor the lock date message At the moment, the lock date message is generated in _compute_tax_lock_date_message. We delegate it to a separate function in order to use this message elsewhere as well. Note: this refactor introduces minor changes in behaviour: - we remove the second part of the lock date message (that mentions other lock dates than the most blocking one), because it is too much information. - we calculate the new accounting date from the existing accounting date rather than from the existing invoice date. This should not change anything in practice, since the new accounting date will be the last day of the period after the lock date. task-2823170 Part-of: odoo/odoo#121566 --- addons/account/i18n/account.pot | 7 ----- addons/account/models/account_move.py | 39 ++++++++++++++------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 72e95683b3b0..19c9152b97ed 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -49,13 +49,6 @@ msgstr "" msgid " (<b>%(amount)s</b> if paid before <b>%(date)s</b>)" msgstr "" -#. module: account -#. odoo-python -#: code:addons/account/models/account_move.py:0 -#, python-format -msgid " The %(lock_type)s lock date is set on %(lock_date)s." -msgstr "" - #. module: account #: model:ir.model.fields,field_description:account.field_account_payment__reconciled_bills_count msgid "# Reconciled Bills" diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 8a5a491e9f8a..1a0eca7d95fb 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1275,26 +1275,9 @@ class AccountMove(models.Model): @api.depends('date', 'line_ids.debit', 'line_ids.credit', 'line_ids.tax_line_id', 'line_ids.tax_ids', 'line_ids.tax_tag_ids') def _compute_tax_lock_date_message(self): for move in self: - invoice_date = move.invoice_date or fields.Date.context_today(move) accounting_date = move.date or fields.Date.context_today(move) affects_tax_report = move._affect_tax_report() - lock_dates = move._get_violated_lock_dates(accounting_date, affects_tax_report) - if lock_dates: - accounting_date = move._get_accounting_date(invoice_date, affects_tax_report) - lock_date, lock_type = lock_dates[-1] - tax_lock_date_message = _( - "The date is being set prior to the %(lock_type)s lock date %(lock_date)s. " - "The Journal Entry will be accounted on %(accounting_date)s upon posting.", - lock_type=lock_type, - lock_date=format_date(move.env, lock_date), - accounting_date=format_date(move.env, accounting_date)) - for lock_date, lock_type in lock_dates[:-1]: - tax_lock_date_message += _(" The %(lock_type)s lock date is set on %(lock_date)s.", - lock_type=lock_type, - lock_date=format_date(move.env, lock_date)) - move.tax_lock_date_message = tax_lock_date_message - else: - move.tax_lock_date_message = False + move.tax_lock_date_message = move._get_lock_date_message(accounting_date, affects_tax_report) @api.depends('currency_id') def _compute_display_inactive_currency_warning(self): @@ -3845,6 +3828,26 @@ class AccountMove(models.Model): locks.sort() return locks + def _get_lock_date_message(self, invoice_date, has_tax): + """Get a message describing the latest lock date affecting the specified date. + :param invoice_date: The date to be checked + :param has_tax: If any taxes are involved in the lines of the invoice + :return: a message describing the latest lock date affecting this move and the date it will be + accounted on if posted, or False if no lock dates affect this move. + """ + lock_dates = self._get_violated_lock_dates(invoice_date, has_tax) + if lock_dates: + invoice_date = self._get_accounting_date(invoice_date, has_tax) + lock_date, lock_type = lock_dates[-1] + tax_lock_date_message = _( + "The date is being set prior to the %(lock_type)s lock date %(lock_date)s. " + "The Journal Entry will be accounted on %(invoice_date)s upon posting.", + lock_type=lock_type, + lock_date=format_date(self.env, lock_date), + invoice_date=format_date(self.env, invoice_date)) + return tax_lock_date_message + return False + @api.model def _move_dict_to_preview_vals(self, move_vals, currency_id=None): preview_vals = { -- GitLab