diff --git a/account_lock_date_update/README.rst b/account_lock_date_update/README.rst new file mode 100644 index 000000000..05cb77a6e --- /dev/null +++ b/account_lock_date_update/README.rst @@ -0,0 +1,71 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +======================== +Account Lock Date Update +======================== + +Allow an Account adviser to update locking date without having +access to all technical settings. + +Installation +============ + +Just install it. + +Configuration +============= + +No configuration needed. + +Usage +===== + +To use this module, you need to be an account adviser and go to: + +* Accounting -> Configuration -> Accounting -> Update accounting lock dates +* Change values and click on update button + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/92/10.0 + +.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt +.. branch is "8.0" for example + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Benjamin Willig + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/account_lock_date_update/__init__.py b/account_lock_date_update/__init__.py new file mode 100644 index 000000000..5cb1c4914 --- /dev/null +++ b/account_lock_date_update/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/account_lock_date_update/__manifest__.py b/account_lock_date_update/__manifest__.py new file mode 100644 index 000000000..8499968b7 --- /dev/null +++ b/account_lock_date_update/__manifest__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Account Lock Date Update', + 'summary': """ + Allow an Account adviser to update locking date without having + access to all technical settings""", + 'version': '10.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/account-financial-tools', + 'depends': [ + 'account', + ], + 'data': [ + 'wizards/account_update_lock_date.xml', + ], +} diff --git a/account_lock_date_update/static/description/icon.png b/account_lock_date_update/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_lock_date_update/static/description/icon.png differ diff --git a/account_lock_date_update/tests/__init__.py b/account_lock_date_update/tests/__init__.py new file mode 100644 index 000000000..df0f306b0 --- /dev/null +++ b/account_lock_date_update/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_lock_date_update 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 new file mode 100644 index 000000000..6838dcf2f --- /dev/null +++ b/account_lock_date_update/tests/test_account_lock_date_update.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase +from odoo.exceptions import UserError + + +class TestAccountLockDateUpdate(TransactionCase): + + def setUp(self): + super(TestAccountLockDateUpdate, self).setUp() + self.UpdateLockDateUpdateObj = self.env['account.update.lock_date'] + + 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') + + def create_account_lock_date_update(self): + 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)], + }) + + with self.assertRaises(UserError): + wizard.sudo(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-01-01', + 'fiscalyear_lock_date': '2000-01-01', + }) + + self.demo_user.write({ + 'groups_id': [(4, self.adviser_group.id)], + }) + + wizard.sudo(self.demo_user.id).execute() diff --git a/account_lock_date_update/wizards/__init__.py b/account_lock_date_update/wizards/__init__.py new file mode 100644 index 000000000..d65accae4 --- /dev/null +++ b/account_lock_date_update/wizards/__init__.py @@ -0,0 +1 @@ +from . import account_update_lock_date diff --git a/account_lock_date_update/wizards/account_update_lock_date.py b/account_lock_date_update/wizards/account_update_lock_date.py new file mode 100644 index 000000000..6f5aa9901 --- /dev/null +++ b/account_lock_date_update/wizards/account_update_lock_date.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# 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.exceptions import UserError + + +class AccountUpdateLockDate(models.TransientModel): + + _name = 'account.update.lock_date' + _description = 'Account Update Lock_date' + + company_id = fields.Many2one( + comodel_name='res.company', string="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.") + 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.") + + @api.model + def default_get(self, field_list): + res = super(AccountUpdateLockDate, self).default_get(field_list) + company = self.env.user.company_id + res.update({ + 'company_id': company.id, + 'period_lock_date': company.period_lock_date, + 'fiscalyear_lock_date': company.fiscalyear_lock_date, + }) + 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() + self.company_id.sudo().write({ + 'period_lock_date': self.period_lock_date, + 'fiscalyear_lock_date': self.fiscalyear_lock_date, + }) diff --git a/account_lock_date_update/wizards/account_update_lock_date.xml b/account_lock_date_update/wizards/account_update_lock_date.xml new file mode 100644 index 000000000..48caff625 --- /dev/null +++ b/account_lock_date_update/wizards/account_update_lock_date.xml @@ -0,0 +1,44 @@ + + + + + + + account.update.lock_date.form (in account_lock_date_update) + account.update.lock_date + +
+
+ + + + + + + +
+
+ + + + + + + Update accounting lock dates + account.update.lock_date + form + new + + + + Update accounting lock dates + + + + + + +