diff --git a/account_lock_to_date/__manifest__.py b/account_lock_to_date/__manifest__.py index 3cbc24256..b33ef4476 100644 --- a/account_lock_to_date/__manifest__.py +++ b/account_lock_to_date/__manifest__.py @@ -5,7 +5,7 @@ "name": "Account Lock To Date", "summary": """ Allows to set an account lock date in the future.""", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "license": "AGPL-3", "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", diff --git a/account_lock_to_date/models/account_move.py b/account_lock_to_date/models/account_move.py index a6a841dde..574ef9db8 100644 --- a/account_lock_to_date/models/account_move.py +++ b/account_lock_to_date/models/account_move.py @@ -1,15 +1,13 @@ # Copyright 2019 ForgeFlow S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import _, api, models +from odoo import _, models from odoo.exceptions import UserError class AccountMove(models.Model): _inherit = "account.move" - @api.multi - def _check_lock_date(self): - res = super()._check_lock_date() + def _check_lock_to_dates(self): for move in self: lock_to_date = ( min( @@ -34,4 +32,15 @@ class AccountMove(models.Model): "with the 'Adviser' role" ) % (lock_to_date) raise UserError(message) - return res + + def action_post(self): + self._check_lock_to_dates() + return super().action_post() + + def button_cancel(self): + self._check_lock_to_dates() + return super().button_cancel() + + def button_draft(self): + self._check_lock_to_dates() + return super().button_draft() diff --git a/account_lock_to_date/models/res_company.py b/account_lock_to_date/models/res_company.py index 177955062..0c9f1b14b 100644 --- a/account_lock_to_date/models/res_company.py +++ b/account_lock_to_date/models/res_company.py @@ -7,7 +7,7 @@ from time import mktime from dateutil.relativedelta import relativedelta -from odoo import SUPERUSER_ID, _, api, fields, models +from odoo import SUPERUSER_ID, _, fields, models from odoo.exceptions import ValidationError from odoo.tools.misc import DEFAULT_SERVER_DATE_FORMAT @@ -28,14 +28,12 @@ class ResCompany(models.Model): "this date. Use it for fiscal year locking for example.", ) - @api.multi def write(self, vals): # fiscalyear_lock_date can't be set to a prior date if "fiscalyear_lock_to_date" in vals or "period_lock_to_date" in vals: self._check_lock_to_dates(vals) return super(ResCompany, self).write(vals) - @api.multi def _check_lock_to_dates(self, vals): """Check the lock to dates for the current companies. @@ -118,7 +116,6 @@ class ResCompany(models.Model): ) ) - @api.multi def _validate_fiscalyear_lock(self, values): res = super()._validate_fiscalyear_lock(values) if values.get("fiscalyear_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 c419ff593..9bbddfe3e 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 @@ -14,9 +14,9 @@ class TestAccountLockToDateUpdate(TransactionCase): self.company = self.env.ref("base.main_company") self.demo_user = self.env.ref("base.user_demo") self.adviser_group = self.env.ref("account.group_account_manager") - self.UpdateLockToDateUpdateObj = self.env["account.update.lock_to_date"].sudo( - self.demo_user - ) + self.UpdateLockToDateUpdateObj = self.env[ + "account.update.lock_to_date" + ].with_user(self.demo_user) self.AccountObj = self.env["account.account"] self.AccountJournalObj = self.env["account.journal"] self.AccountMoveObj = self.env["account.move"] @@ -89,7 +89,7 @@ class TestAccountLockToDateUpdate(TransactionCase): ) self.demo_user.write({"groups_id": [(3, self.adviser_group.id)]}) with self.assertRaises(UserError): - wizard.sudo(self.demo_user.id).execute() + wizard.with_user(self.demo_user.id).execute() def test_02_update_with_access(self): wizard = self.create_account_lock_date_update() @@ -100,7 +100,7 @@ class TestAccountLockToDateUpdate(TransactionCase): } ) self.demo_user.write({"groups_id": [(4, self.adviser_group.id)]}) - wizard.sudo(self.demo_user.id).execute() + wizard.with_user(self.demo_user.id).execute() self.assertEqual( self.company.period_lock_to_date, datetime.strptime("2900-01-01", DEFAULT_SERVER_DATE_FORMAT).date(), @@ -117,7 +117,7 @@ class TestAccountLockToDateUpdate(TransactionCase): self.company.fiscalyear_lock_to_date = "2900-02-01" move = self.create_account_move("2900-01-01") with self.assertRaises(UserError): - move.sudo(self.demo_user.id).post() + move.with_user(self.demo_user.id).action_post() def test_04_create_move_inside_period(self): """We test that we can successfully create a journal entry @@ -125,7 +125,7 @@ class TestAccountLockToDateUpdate(TransactionCase): self.company.period_lock_to_date = "2900-01-01" self.company.fiscalyear_lock_to_date = "2900-02-01" move = self.create_account_move("2800-01-01") - move.sudo(self.demo_user.id).post() + move.with_user(self.demo_user.id).action_post() self.assertEqual(move.state, "posted") def test_05_lock_period_with_draft_moves(self): diff --git a/account_lock_to_date/wizards/account_update_lock_to_date.py b/account_lock_to_date/wizards/account_update_lock_to_date.py index 254072d4d..4e0cb063d 100644 --- a/account_lock_to_date/wizards/account_update_lock_to_date.py +++ b/account_lock_to_date/wizards/account_update_lock_to_date.py @@ -41,14 +41,12 @@ class AccountUpdateLockToDate(models.TransientModel): ) return res - @api.multi def _check_execute_allowed(self): self.ensure_one() has_adviser_group = self.env.user.has_group("account.group_account_manager") if not (has_adviser_group or self.env.uid == SUPERUSER_ID): raise UserError(_("You are not allowed to execute this action.")) - @api.multi def execute(self): self.ensure_one() self._check_execute_allowed() diff --git a/account_lock_to_date/wizards/account_update_lock_to_date.xml b/account_lock_to_date/wizards/account_update_lock_to_date.xml index 5af8e85a7..2d1e8086e 100644 --- a/account_lock_to_date/wizards/account_update_lock_to_date.xml +++ b/account_lock_to_date/wizards/account_update_lock_to_date.xml @@ -1,44 +1,50 @@ - + - account.update.lock_to_date.form account.update.lock_to_date
-
+
- - - + + +
-
- - Update accounting lock to dates account.update.lock_to_date form new - Update accounting lock to dates - - - - + + + + -