2
0

account_journal_lock_date: no need to inherit write()

This commit is contained in:
Alexis de Lattre 2023-01-09 12:57:48 +01:00 committed by Rodrigo
parent 0c5b530e84
commit 6f220a3269
2 changed files with 14 additions and 66 deletions

View File

@ -10,11 +10,6 @@ class AccountMove(models.Model):
_inherit = "account.move" _inherit = "account.move"
def write(self, values):
res = super().write(values)
self._check_fiscalyear_lock_date()
return res
def _check_fiscalyear_lock_date(self): def _check_fiscalyear_lock_date(self):
res = super()._check_fiscalyear_lock_date() res = super()._check_fiscalyear_lock_date()
if self.env.context.get("bypass_journal_lock_date"): if self.env.context.get("bypass_journal_lock_date"):

View File

@ -60,39 +60,15 @@ class TestJournalLockDate(common.AccountTestInvoicingCommon):
) )
self.assertFalse(self.env.user.has_group("account.group_account_manager")) self.assertFalse(self.env.user.has_group("account.group_account_manager"))
# Test that the move cannot be created, written, or cancelled # Test that the move cannot be written, or cancelled
with self.assertRaises(UserError): with self.assertRaisesRegex(
self.account_move_obj.create( UserError, ".*prior to and inclusive of the lock date.*"
{ ):
"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):
self.move.write({"name": "TEST"}) 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() self.move.button_cancel()
# create a move after the 'Lock Date for Non-Advisers' and post it # 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() wizard.action_update_lock_dates()
# Advisers cannot create, write, or cancel moves before 'Lock Date' # Advisers cannot write, or cancel moves before 'Lock Date'
with self.assertRaises(UserError): with self.assertRaisesRegex(
self.account_move_obj.create( UserError, ".*prior to and inclusive of the lock date.*"
{ ):
"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):
self.move.write({"name": "TEST"}) 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() self.move.button_cancel()
# Advisers can create movements on a date after the 'Lock Date' # Advisers can create movements on a date after the 'Lock Date'
# even if that date is before and inclusive of # even if that date is before and inclusive of