[FIX] account: accrual and lock dates

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 <qdp@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
william
2022-03-29 20:21:22 +02:00
parent 7e37cc297d
commit 9b9ed45c5a
2 changed files with 24 additions and 1 deletions
+12
View File
@@ -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
@@ -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)