From ae5453775ba7ca6072d1e97ef3bb3d2d4bc03752 Mon Sep 17 00:00:00 2001 From: "Ricardo Gomes Rodrigues (rigr)" Date: Fri, 23 Sep 2022 07:16:49 +0000 Subject: [PATCH] [FIX] account: prevent resequence of an invoice if it's in a locked period Currently, the user can resequence invoices that are in a locked period. This is not desirable, this commit fixes this. closes odoo/odoo#102469 X-original-commit: b1009e4aa514215054de44544a8914c16932f55e Related: odoo/enterprise#32423 Signed-off-by: Quentin De Paoli Signed-off-by: Ricardo Gomes Rodrigues (rigr) --- addons/account/models/account_move.py | 7 +++++-- addons/account/tests/test_account_move_entry.py | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index f64791e1e20..2f9bba28fe7 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2179,8 +2179,11 @@ class AccountMove(models.Model): if (move.name and move.name != '/' and move.sequence_number not in (0, 1) and 'journal_id' in vals and move.journal_id.id != vals['journal_id']): raise UserError(_('You cannot edit the journal of an account move if it already has a sequence number assigned.')) - # You can't change the date of a move being inside a locked period. - if move.state == "posted" and 'date' in vals and move.date != vals['date']: + # You can't change the date or name of a move being inside a locked period. + if move.state == "posted" and ( + ('name' in vals and move.name != vals['name']) + or ('date' in vals and move.date != vals['date']) + ): move._check_fiscalyear_lock_date() move.line_ids._check_tax_lock_date() diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index eafc065d0ce..f0ece9ccfa4 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -197,6 +197,9 @@ class TestAccountMove(AccountTestInvoicingCommon): with self.assertRaises(UserError), self.cr.savepoint(): self.test_move.date = fields.Date.from_string('2018-01-01') + with self.assertRaises(UserError), self.cr.savepoint(): + self.test_move.name = "Othername" + with self.assertRaises(UserError), self.cr.savepoint(): self.test_move.unlink() @@ -304,6 +307,9 @@ class TestAccountMove(AccountTestInvoicingCommon): with self.assertRaises(UserError), self.cr.savepoint(): self.test_move.date = fields.Date.from_string('2018-01-01') + with self.assertRaises(UserError), self.cr.savepoint(): + self.test_move.name = "Othername" + with self.assertRaises(UserError), self.cr.savepoint(): self.test_move.unlink()