From 9b9ed45c5a325d1b8a95aeeecb3b5391327da226 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 11 Mar 2022 12:40:11 +0000 Subject: [PATCH] [FIX] account: accrual and lock dates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not allow users to create accrual entries for locked periods. This would either create an entry for another date, since the date is changed automatically by `_get_accounting_date` when posting. Reproduce: * Set a lock date * Do an automatic entry for either changing the account or the period before that lock date Or it would traceback because the date would be changed automatically and no matching would be possible when changing the period. * Set a lock date * Create an automatic entry to change the period of an entry before the tax lock date closes odoo/odoo#87391 X-original-commit: f830b008781c2f6f5644395688654e64edd5c836 Signed-off-by: Quentin De Paoli Signed-off-by: William André (wan) --- addons/account/i18n/account.pot | 12 ++++++++++++ .../wizard/account_automatic_entry_wizard.py | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index f480b119a7b..87ffdce8fb6 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -13131,6 +13131,18 @@ msgid "" " There is nothing left to process." msgstr "" +#. module: account +#: code:addons/account/wizard/account_automatic_entry_wizard.py:0 +#, python-format +msgid "The date of some related entries is protected by a lock date" +msgstr "" + +#. module: account +#: code:addons/account/wizard/account_automatic_entry_wizard.py:0 +#, python-format +msgid "The date selected is protected by a lock date" +msgstr "" + #. module: account #: code:addons/account/models/account_payment_term.py:0 #, python-format diff --git a/addons/account/wizard/account_automatic_entry_wizard.py b/addons/account/wizard/account_automatic_entry_wizard.py index 6632c64f1b5..29965770f01 100644 --- a/addons/account/wizard/account_automatic_entry_wizard.py +++ b/addons/account/wizard/account_automatic_entry_wizard.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from odoo import api, fields, models, _ -from odoo.exceptions import UserError +from odoo.exceptions import UserError, ValidationError from odoo.tools.misc import format_date, formatLang from collections import defaultdict @@ -106,6 +106,17 @@ class AutomaticEntryWizard(models.TransientModel): for record in self: record.display_currency_helper = bool(record.destination_account_id.currency_id) + @api.constrains('date', 'move_line_ids') + def _check_date(self): + for wizard in self: + if wizard.move_line_ids.move_id._get_violated_lock_dates(wizard.date, False): + raise ValidationError(_("The date selected is protected by a lock date")) + + if wizard.action == 'change_period': + for move in wizard.move_line_ids.move_id: + if move._get_violated_lock_dates(move.date, False): + raise ValidationError(_("The date of some related entries is protected by a lock date")) + @api.model def default_get(self, fields): res = super().default_get(fields)