From 6f220a32699731a71b57d8ce5adf1124b6306c8b Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 9 Jan 2023 12:57:48 +0100 Subject: [PATCH] account_journal_lock_date: no need to inherit write() --- .../models/account_move.py | 5 -- .../tests/test_journal_lock_date.py | 75 ++++--------------- 2 files changed, 14 insertions(+), 66 deletions(-) diff --git a/account_journal_lock_date/models/account_move.py b/account_journal_lock_date/models/account_move.py index b194168e..3e86d25d 100644 --- a/account_journal_lock_date/models/account_move.py +++ b/account_journal_lock_date/models/account_move.py @@ -10,11 +10,6 @@ class AccountMove(models.Model): _inherit = "account.move" - def write(self, values): - res = super().write(values) - self._check_fiscalyear_lock_date() - return res - def _check_fiscalyear_lock_date(self): res = super()._check_fiscalyear_lock_date() if self.env.context.get("bypass_journal_lock_date"): diff --git a/account_journal_lock_date/tests/test_journal_lock_date.py b/account_journal_lock_date/tests/test_journal_lock_date.py index daf3ef0c..c165f8c4 100644 --- a/account_journal_lock_date/tests/test_journal_lock_date.py +++ b/account_journal_lock_date/tests/test_journal_lock_date.py @@ -60,39 +60,15 @@ class TestJournalLockDate(common.AccountTestInvoicingCommon): ) self.assertFalse(self.env.user.has_group("account.group_account_manager")) - # Test that the move cannot be created, written, or cancelled - with self.assertRaises(UserError): - self.account_move_obj.create( - { - "date": date.today(), - "journal_id": self.journal.id, - "line_ids": [ - ( - 0, - 0, - { - "account_id": self.account.id, - "credit": 1000.0, - "name": "Credit line", - }, - ), - ( - 0, - 0, - { - "account_id": self.account2.id, - "debit": 1000.0, - "name": "Debit line", - }, - ), - ], - } - ) - - with self.assertRaises(UserError): + # Test that the move cannot be written, or cancelled + with self.assertRaisesRegex( + UserError, ".*prior to and inclusive of the lock date.*" + ): self.move.write({"name": "TEST"}) - with self.assertRaises(UserError): + with self.assertRaisesRegex( + UserError, ".*prior to and inclusive of the lock date.*" + ): self.move.button_cancel() # create a move after the 'Lock Date for Non-Advisers' and post it @@ -172,38 +148,15 @@ class TestJournalLockDate(common.AccountTestInvoicingCommon): ) ) wizard.action_update_lock_dates() - # Advisers cannot create, write, or cancel moves before 'Lock Date' - with self.assertRaises(UserError): - self.account_move_obj.create( - { - "date": date.today(), - "journal_id": self.journal.id, - "line_ids": [ - ( - 0, - 0, - { - "account_id": self.account.id, - "credit": 1000.0, - "name": "Credit line", - }, - ), - ( - 0, - 0, - { - "account_id": self.account2.id, - "debit": 1000.0, - "name": "Debit line", - }, - ), - ], - } - ) - with self.assertRaises(UserError): + # Advisers cannot write, or cancel moves before 'Lock Date' + with self.assertRaisesRegex( + UserError, ".*prior to and inclusive of the lock date.*" + ): self.move.write({"name": "TEST"}) - with self.assertRaises(UserError): + with self.assertRaisesRegex( + UserError, ".*prior to and inclusive of the lock date.*" + ): self.move.button_cancel() # Advisers can create movements on a date after the 'Lock Date' # even if that date is before and inclusive of