diff --git a/account_lock_to_date/models/account_move.py b/account_lock_to_date/models/account_move.py index d61cc7575dc..8caa9a2804b 100644 --- a/account_lock_to_date/models/account_move.py +++ b/account_lock_to_date/models/account_move.py @@ -15,6 +15,8 @@ def _check_lock_to_dates(self): Other users will also be restricted by the period_lock_to_date. """ is_advisor = self.user_has_groups("account.group_account_manager") + if self.env.context.get("bypass_account_lock_to_date"): + return for move in self: advisor_lock_to_date = move.company_id.fiscalyear_lock_to_date user_lock_to_date = move.company_id.period_lock_to_date diff --git a/account_lock_to_date/tests/test_account_lock_to_date_update.py b/account_lock_to_date/tests/test_account_lock_to_date_update.py index d6bdd2c2e00..29fe71acb81 100644 --- a/account_lock_to_date/tests/test_account_lock_to_date_update.py +++ b/account_lock_to_date/tests/test_account_lock_to_date_update.py @@ -135,3 +135,13 @@ def test_05_lock_period_with_draft_moves(self): with self.assertRaises(ValidationError): self.company.period_lock_to_date = "2900-01-01" self.company.fiscalyear_lock_to_date = "2900-02-01" + + def test_06_lock_period_with_bypass(self): + """We test that journal entries can be posted after the locked date + when the bypass option is enabled.""" + self.company.period_lock_to_date = "2900-01-01" + self.company.fiscalyear_lock_to_date = "2900-02-01" + move = self.create_account_move("2900-01-01").with_context( + bypass_account_lock_to_date=True + ) + move.with_user(self.demo_user.id).action_post()