diff --git a/account_lock_date_update/__manifest__.py b/account_lock_date_update/__manifest__.py index bb59d6e7..9ef82af2 100644 --- a/account_lock_date_update/__manifest__.py +++ b/account_lock_date_update/__manifest__.py @@ -6,7 +6,7 @@ 'summary': """ Allow an Account adviser to update locking date without having access to all technical settings""", - 'version': '12.0.1.0.0', + 'version': '13.0.1.0.0', 'license': 'AGPL-3', 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', 'website': 'https://github.com/OCA/account-financial-tools', diff --git a/account_lock_date_update/readme/CONTRIBUTORS.rst b/account_lock_date_update/readme/CONTRIBUTORS.rst index 74768695..75f834f1 100644 --- a/account_lock_date_update/readme/CONTRIBUTORS.rst +++ b/account_lock_date_update/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Benjamin Willig * Fekete Mihai * Kitti Upariphutthiphong +* Andrea Stirpe diff --git a/account_lock_date_update/tests/test_account_lock_date_update.py b/account_lock_date_update/tests/test_account_lock_date_update.py index 2bdedadb..25b12c34 100644 --- a/account_lock_date_update/tests/test_account_lock_date_update.py +++ b/account_lock_date_update/tests/test_account_lock_date_update.py @@ -9,13 +9,13 @@ from odoo.exceptions import UserError class TestAccountLockDateUpdate(TransactionCase): def setUp(self): - super(TestAccountLockDateUpdate, self).setUp() + super().setUp() 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.UpdateLockDateUpdateObj = self.env[ 'account.update.lock_date' - ].sudo(self.demo_user) + ].with_user(self.demo_user) def create_account_lock_date_update(self): return self.UpdateLockDateUpdateObj.create({ @@ -32,7 +32,7 @@ class TestAccountLockDateUpdate(TransactionCase): '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() @@ -43,7 +43,7 @@ class TestAccountLockDateUpdate(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( fields.Date.to_string(self.company.period_lock_date), '2000-02-01') diff --git a/account_lock_date_update/wizards/account_update_lock_date.py b/account_lock_date_update/wizards/account_update_lock_date.py index 95fce131..9368e160 100644 --- a/account_lock_date_update/wizards/account_update_lock_date.py +++ b/account_lock_date_update/wizards/account_update_lock_date.py @@ -1,7 +1,7 @@ # Copyright 2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models, SUPERUSER_ID, _ +from odoo import api, fields, models, _ from odoo.exceptions import UserError @@ -10,7 +10,7 @@ class AccountUpdateLockDate(models.TransientModel): _description = 'Account Update Lock_date' company_id = fields.Many2one( - comodel_name='res.company', string="Company", required=True) + comodel_name='res.company', required=True) period_lock_date = fields.Date( string="Lock Date for Non-Advisers", help="Only users with the 'Adviser' role can edit accounts prior to " @@ -24,8 +24,8 @@ class AccountUpdateLockDate(models.TransientModel): @api.model def default_get(self, field_list): - res = super(AccountUpdateLockDate, self).default_get(field_list) - company = self.env.user.company_id + res = super().default_get(field_list) + company = self.env.company res.update({ 'company_id': company.id, 'period_lock_date': company.period_lock_date, @@ -33,15 +33,12 @@ class AccountUpdateLockDate(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): + has_adviser_group = self.env.user.has_group('account.group_account_manager') + if not (has_adviser_group or self.env.user._is_admin()): 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_date_update/wizards/account_update_lock_date.xml b/account_lock_date_update/wizards/account_update_lock_date.xml index cb24a426..05a6c769 100644 --- a/account_lock_date_update/wizards/account_update_lock_date.xml +++ b/account_lock_date_update/wizards/account_update_lock_date.xml @@ -4,7 +4,7 @@ - + account.update.lock_date.form (in account_lock_date_update) account.update.lock_date @@ -12,9 +12,13 @@
- - - + + + + + + +