From f804ff9398f158e06d5e5f028216bf84c42d2178 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 17 Jan 2020 11:41:26 +0100 Subject: [PATCH] pre-commit --- account_lock_date_update/__manifest__.py | 22 ++++----- .../tests/test_account_lock_date_update.py | 49 ++++++++----------- .../wizards/account_update_lock_date.py | 43 +++++++++------- 3 files changed, 53 insertions(+), 61 deletions(-) diff --git a/account_lock_date_update/__manifest__.py b/account_lock_date_update/__manifest__.py index 9ef82af22..e7abefec6 100644 --- a/account_lock_date_update/__manifest__.py +++ b/account_lock_date_update/__manifest__.py @@ -2,19 +2,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Account Lock Date Update', - 'summary': """ + "name": "Account Lock Date Update", + "summary": """ Allow an Account adviser to update locking date without having access to all technical settings""", - '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', - 'installable': True, - 'depends': [ - 'account', - ], - 'data': [ - 'wizards/account_update_lock_date.xml', - ], + "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", + "installable": True, + "depends": ["account"], + "data": ["wizards/account_update_lock_date.xml"], } 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 25b12c344..a572b1f06 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 @@ -2,51 +2,42 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields -from odoo.tests.common import TransactionCase from odoo.exceptions import UserError +from odoo.tests.common import TransactionCase class TestAccountLockDateUpdate(TransactionCase): - def setUp(self): 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' - ].with_user(self.demo_user) + 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"].with_user( + self.demo_user + ) def create_account_lock_date_update(self): - return self.UpdateLockDateUpdateObj.create({ - 'company_id': self.company.id, - }) + return self.UpdateLockDateUpdateObj.create({"company_id": self.company.id}) def test_01_update_without_access(self): wizard = self.create_account_lock_date_update() - wizard.write({ - 'period_lock_date': '2000-01-01', - 'fiscalyear_lock_date': '2000-01-01', - }) - self.demo_user.write({ - 'groups_id': [(3, self.adviser_group.id)], - }) + wizard.write( + {"period_lock_date": "2000-01-01", "fiscalyear_lock_date": "2000-01-01"} + ) + self.demo_user.write({"groups_id": [(3, self.adviser_group.id)]}) with self.assertRaises(UserError): wizard.with_user(self.demo_user.id).execute() def test_02_update_with_access(self): wizard = self.create_account_lock_date_update() - wizard.write({ - 'period_lock_date': '2000-02-01', - 'fiscalyear_lock_date': '2000-01-01', - }) - self.demo_user.write({ - 'groups_id': [(4, self.adviser_group.id)], - }) + wizard.write( + {"period_lock_date": "2000-02-01", "fiscalyear_lock_date": "2000-01-01"} + ) + self.demo_user.write({"groups_id": [(4, self.adviser_group.id)]}) wizard.with_user(self.demo_user.id).execute() self.assertEqual( - fields.Date.to_string(self.company.period_lock_date), - '2000-02-01') + fields.Date.to_string(self.company.period_lock_date), "2000-02-01" + ) self.assertEqual( - fields.Date.to_string(self.company.fiscalyear_lock_date), - '2000-01-01') + fields.Date.to_string(self.company.fiscalyear_lock_date), "2000-01-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 9368e1603..6912b81bf 100644 --- a/account_lock_date_update/wizards/account_update_lock_date.py +++ b/account_lock_date_update/wizards/account_update_lock_date.py @@ -1,48 +1,53 @@ # Copyright 2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models, _ +from odoo import _, api, fields, models from odoo.exceptions import UserError class AccountUpdateLockDate(models.TransientModel): - _name = 'account.update.lock_date' - _description = 'Account Update Lock_date' + _name = "account.update.lock_date" + _description = "Account Update Lock_date" - company_id = fields.Many2one( - comodel_name='res.company', required=True) + company_id = fields.Many2one(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 " - "and inclusive of this date. Use it for period locking inside an " - "open fiscal year, for example.") + "and inclusive of this date. Use it for period locking inside an " + "open fiscal year, for example.", + ) fiscalyear_lock_date = fields.Date( string="Lock Date", help="No users, including Advisers, can edit accounts prior to and " - "inclusive of this date. Use it for fiscal year locking for " - "example.") + "inclusive of this date. Use it for fiscal year locking for " + "example.", + ) @api.model def default_get(self, field_list): res = super().default_get(field_list) company = self.env.company - res.update({ - 'company_id': company.id, - 'period_lock_date': company.period_lock_date, - 'fiscalyear_lock_date': company.fiscalyear_lock_date, - }) + res.update( + { + "company_id": company.id, + "period_lock_date": company.period_lock_date, + "fiscalyear_lock_date": company.fiscalyear_lock_date, + } + ) return res def _check_execute_allowed(self): self.ensure_one() - has_adviser_group = self.env.user.has_group('account.group_account_manager') + 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.")) def execute(self): self.ensure_one() self._check_execute_allowed() - self.company_id.sudo().write({ - 'period_lock_date': self.period_lock_date, - 'fiscalyear_lock_date': self.fiscalyear_lock_date, - }) + self.company_id.sudo().write( + { + "period_lock_date": self.period_lock_date, + "fiscalyear_lock_date": self.fiscalyear_lock_date, + } + )