diff --git a/account_lock_to_date/models/res_company.py b/account_lock_to_date/models/res_company.py index 5a354272756..ca885163064 100644 --- a/account_lock_to_date/models/res_company.py +++ b/account_lock_to_date/models/res_company.py @@ -68,7 +68,7 @@ def _check_lock_to_dates(self, vals): if ( old_fiscalyear_lock_to_date and fiscalyear_lock_to_date - and fiscalyear_lock_to_date > old_fiscalyear_lock_to_date + and fiscalyear_lock_to_date < old_fiscalyear_lock_to_date ): raise ValidationError( _( 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 ee5c613475b..828dea1cc45 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 @@ -111,6 +111,30 @@ def test_02_update_with_access(self): datetime.strptime("2900-02-01", DEFAULT_SERVER_DATE_FORMAT).date(), ) + def test_02b_update_to_later_date_succeeds(self): + """We test that updating the fiscalyear_lock_to_date to a LATER + date than the current one succeeds (this was the bug: the old + code incorrectly rejected later dates instead of earlier ones).""" + self.company.fiscalyear_lock_to_date = "2900-01-01" + wizard = self.create_account_lock_date_update() + wizard.write({"fiscalyear_lock_to_date": "2900-02-01"}) + self.demo_user.write({"groups_id": [(4, self.adviser_group.id)]}) + wizard.with_user(self.demo_user.id).execute() + self.assertEqual( + self.company.fiscalyear_lock_to_date, + datetime.strptime("2900-02-01", DEFAULT_SERVER_DATE_FORMAT).date(), + ) + + def test_02c_update_to_earlier_date_fails(self): + """We test that updating the fiscalyear_lock_to_date to an + EARLIER date than the current one is rejected.""" + self.company.fiscalyear_lock_to_date = "2900-02-01" + wizard = self.create_account_lock_date_update() + wizard.write({"fiscalyear_lock_to_date": "2900-01-01"}) + self.demo_user.write({"groups_id": [(4, self.adviser_group.id)]}) + with self.assertRaises(ValidationError): + wizard.with_user(self.demo_user.id).execute() + def test_03_create_move_outside_period(self): """We test that we cannot create journal entries after the locked date"""