From 3cd958dbcd246113bf2c3006d6c7854af2c46bd5 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Thu, 12 Dec 2024 12:52:33 +0100 Subject: [PATCH] [ADD] account_tax_lock_group --- account_tax_lock_group/README.rst | 100 ++++ account_tax_lock_group/__init__.py | 3 + account_tax_lock_group/__manifest__.py | 20 + account_tax_lock_group/i18n/it.po | 26 ++ account_tax_lock_group/models/__init__.py | 3 + account_tax_lock_group/models/res_company.py | 31 ++ account_tax_lock_group/readme/CONFIGURE.rst | 1 + .../readme/CONTRIBUTORS.rst | 3 + account_tax_lock_group/readme/DESCRIPTION.rst | 3 + account_tax_lock_group/readme/USAGE.rst | 3 + .../security/res_company_security.xml | 17 + .../static/description/index.html | 440 ++++++++++++++++++ account_tax_lock_group/tests/__init__.py | 3 + .../tests/test_update_lock_dates.py | 63 +++ .../odoo/addons/account_tax_lock_group | 1 + setup/account_tax_lock_group/setup.py | 6 + 16 files changed, 723 insertions(+) create mode 100644 account_tax_lock_group/README.rst create mode 100644 account_tax_lock_group/__init__.py create mode 100644 account_tax_lock_group/__manifest__.py create mode 100644 account_tax_lock_group/i18n/it.po create mode 100644 account_tax_lock_group/models/__init__.py create mode 100644 account_tax_lock_group/models/res_company.py create mode 100644 account_tax_lock_group/readme/CONFIGURE.rst create mode 100644 account_tax_lock_group/readme/CONTRIBUTORS.rst create mode 100644 account_tax_lock_group/readme/DESCRIPTION.rst create mode 100644 account_tax_lock_group/readme/USAGE.rst create mode 100644 account_tax_lock_group/security/res_company_security.xml create mode 100644 account_tax_lock_group/static/description/index.html create mode 100644 account_tax_lock_group/tests/__init__.py create mode 100644 account_tax_lock_group/tests/test_update_lock_dates.py create mode 120000 setup/account_tax_lock_group/odoo/addons/account_tax_lock_group create mode 100644 setup/account_tax_lock_group/setup.py diff --git a/account_tax_lock_group/README.rst b/account_tax_lock_group/README.rst new file mode 100644 index 00000000000..f88e245404f --- /dev/null +++ b/account_tax_lock_group/README.rst @@ -0,0 +1,100 @@ +================== +Account Lock Group +================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f9d58ea13f06c9e1cb56b057db47dcc9ba7bd19615c6d7a069d1d38de95127bd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github + :target: https://github.com/OCA/account-financial-tools/tree/16.0/account_tax_lock_group + :alt: OCA/account-financial-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_tax_lock_group + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +If a user is in the group "Update tax lock date without restrictions", they can update the "Tax Return Lock Date" (`tax_lock_date`) without raising any exception. + +Updating such date is usually restricted for a good reason, so update it at your own risk. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Add the user to group "Update tax lock date without restrictions". + +Usage +===== + +Account lock dates can be updated from the User Interface using the OCA module `account_lock_date_update` or the Enterprise module `account_accountant`. + +The added group allows to edit the "Tax Return Lock Date" only when it is the only date being modified. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Aion Tech + +Contributors +~~~~~~~~~~~~ + +* `Aion Tech `_: + + * Simone Rubino + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-SirAionTech| image:: https://github.com/SirAionTech.png?size=40px + :target: https://github.com/SirAionTech + :alt: SirAionTech + +Current `maintainer `__: + +|maintainer-SirAionTech| + +This module is part of the `OCA/account-financial-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_tax_lock_group/__init__.py b/account_tax_lock_group/__init__.py new file mode 100644 index 00000000000..b18eea37960 --- /dev/null +++ b/account_tax_lock_group/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/account_tax_lock_group/__manifest__.py b/account_tax_lock_group/__manifest__.py new file mode 100644 index 00000000000..ce8c381e476 --- /dev/null +++ b/account_tax_lock_group/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Lock Group", + "summary": "Account lock dates can be updated without restrictions by a dedicated group.", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Aion Tech, Odoo Community Association (OCA)", + "maintainers": [ + "SirAionTech", + ], + "website": "https://github.com/OCA/account-financial-tools", + "depends": [ + "account_lock", + ], + "data": [ + "security/res_company_security.xml", + ], +} diff --git a/account_tax_lock_group/i18n/it.po b/account_tax_lock_group/i18n/it.po new file mode 100644 index 00000000000..36f3096b8a4 --- /dev/null +++ b/account_tax_lock_group/i18n/it.po @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_tax_lock_group +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-12-12 13:19+0000\n" +"PO-Revision-Date: 2024-12-12 13:19+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_tax_lock_group +#: model:ir.model,name:account_tax_lock_group.model_res_company +msgid "Companies" +msgstr "Aziende" + +#. module: account_tax_lock_group +#: model:res.groups,name:account_tax_lock_group.account_tax_lock_date_group_manager +msgid "Update tax lock date without restrictions" +msgstr "Aggiornare la data di blocco in contabilità senza restrizioni" \ No newline at end of file diff --git a/account_tax_lock_group/models/__init__.py b/account_tax_lock_group/models/__init__.py new file mode 100644 index 00000000000..04cfe037a45 --- /dev/null +++ b/account_tax_lock_group/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import res_company diff --git a/account_tax_lock_group/models/res_company.py b/account_tax_lock_group/models/res_company.py new file mode 100644 index 00000000000..c5c183862df --- /dev/null +++ b/account_tax_lock_group/models/res_company.py @@ -0,0 +1,31 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import models + + +class ResCompany(models.Model): + _inherit = "res.company" + + def _autorise_lock_date_changes(self, vals): + if self.user_has_groups( + "account_tax_lock_group.account_tax_lock_date_group_manager", + ): + # Check that only the "Tax Return Lock Date" is being modified + check_vals = vals.copy() + lock_date_fields = [ + "period_lock_date", + "fiscalyear_lock_date", + "tax_lock_date", + ] + for lock_date_field in lock_date_fields: + if check_vals.get(lock_date_field) == self.env.company[lock_date_field]: + check_vals.pop(lock_date_field) + + if set(check_vals.keys()) == {"tax_lock_date"}: + # Only the "Tax Return Lock Date" is being modified + # and the user can modify it. + pass + else: + return super()._autorise_lock_date_changes(vals) diff --git a/account_tax_lock_group/readme/CONFIGURE.rst b/account_tax_lock_group/readme/CONFIGURE.rst new file mode 100644 index 00000000000..31a9794449f --- /dev/null +++ b/account_tax_lock_group/readme/CONFIGURE.rst @@ -0,0 +1 @@ +Add the user to group "Update tax lock date without restrictions". diff --git a/account_tax_lock_group/readme/CONTRIBUTORS.rst b/account_tax_lock_group/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..6afa1541b48 --- /dev/null +++ b/account_tax_lock_group/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Aion Tech `_: + + * Simone Rubino diff --git a/account_tax_lock_group/readme/DESCRIPTION.rst b/account_tax_lock_group/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..25c89359bfe --- /dev/null +++ b/account_tax_lock_group/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +If a user is in the group "Update tax lock date without restrictions", they can update the "Tax Return Lock Date" (`tax_lock_date`) without raising any exception. + +Updating such date is usually restricted for a good reason, so update it at your own risk. diff --git a/account_tax_lock_group/readme/USAGE.rst b/account_tax_lock_group/readme/USAGE.rst new file mode 100644 index 00000000000..8f5aaa04744 --- /dev/null +++ b/account_tax_lock_group/readme/USAGE.rst @@ -0,0 +1,3 @@ +Account lock dates can be updated from the User Interface using the OCA module `account_lock_date_update` or the Enterprise module `account_accountant`. + +The added group allows to edit the "Tax Return Lock Date" only when it is the only date being modified. diff --git a/account_tax_lock_group/security/res_company_security.xml b/account_tax_lock_group/security/res_company_security.xml new file mode 100644 index 00000000000..c5d7d34085b --- /dev/null +++ b/account_tax_lock_group/security/res_company_security.xml @@ -0,0 +1,17 @@ + + + + + Update tax lock date without restrictions + + + + diff --git a/account_tax_lock_group/static/description/index.html b/account_tax_lock_group/static/description/index.html new file mode 100644 index 00000000000..a369f4be354 --- /dev/null +++ b/account_tax_lock_group/static/description/index.html @@ -0,0 +1,440 @@ + + + + + +Account Lock Group + + + +
+

Account Lock Group

+ + +

Beta License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

+

If a user is in the group “Update tax lock date without restrictions”, they can update the “Tax Return Lock Date” (tax_lock_date) without raising any exception.

+

Updating such date is usually restricted for a good reason, so update it at your own risk.

+

Table of contents

+ +
+

Configuration

+

Add the user to group “Update tax lock date without restrictions”.

+
+
+

Usage

+

Account lock dates can be updated from the User Interface using the OCA module account_lock_date_update or the Enterprise module account_accountant.

+

The added group allows to edit the “Tax Return Lock Date” only when it is the only date being modified.

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Aion Tech
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

SirAionTech

+

This module is part of the OCA/account-financial-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_tax_lock_group/tests/__init__.py b/account_tax_lock_group/tests/__init__.py new file mode 100644 index 00000000000..96c67aae2bf --- /dev/null +++ b/account_tax_lock_group/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_update_lock_dates diff --git a/account_tax_lock_group/tests/test_update_lock_dates.py b/account_tax_lock_group/tests/test_update_lock_dates.py new file mode 100644 index 00000000000..41b67220767 --- /dev/null +++ b/account_tax_lock_group/tests/test_update_lock_dates.py @@ -0,0 +1,63 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import date + +from odoo.exceptions import UserError +from odoo.tests import new_test_user + +from odoo.addons.base.tests.common import BaseCommon + + +class TestUpdateLockDates(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.group_xmlid = "account_tax_lock_group.account_tax_lock_date_group_manager" + + cls.company = cls.env.company + cls.company.tax_lock_date = date(2020, month=1, day=1) + + cls.restricted_user = new_test_user( + cls.env, + login="Restricted user", + ) + cls.unrestricted_user = new_test_user( + cls.env, + login="Unrestricted user", + groups=f"{cls.group_xmlid},base.group_erp_manager", + ) + + def test_empty_restricted_tax_lock_date(self): + """If a user is not in group, they cannot update the Tax Return Lock Date.""" + # Arrange + group_xmlid = self.group_xmlid + company = self.env.company + restricted_user = self.restricted_user + # pre-condition + self.assertTrue(company.tax_lock_date) + self.assertFalse(restricted_user.has_group(group_xmlid)) + + # Act + with self.assertRaises(UserError) as ue: + company.with_user(restricted_user).tax_lock_date = False + + # Assert + exc_message = ue.exception.args[0] + self.assertIn("date is irreversible", exc_message) + + def test_empty_unrestricted_tax_lock_date(self): + """If a user is in group, they can update the Tax Return Lock Date.""" + # Arrange + group_xmlid = self.group_xmlid + company = self.env.company + unrestricted_user = self.unrestricted_user + # pre-condition + self.assertTrue(company.tax_lock_date) + self.assertTrue(unrestricted_user.has_group(group_xmlid)) + + # Act + company.with_user(unrestricted_user).tax_lock_date = False + + # Assert + self.assertFalse(company.tax_lock_date) diff --git a/setup/account_tax_lock_group/odoo/addons/account_tax_lock_group b/setup/account_tax_lock_group/odoo/addons/account_tax_lock_group new file mode 120000 index 00000000000..364c8663cfe --- /dev/null +++ b/setup/account_tax_lock_group/odoo/addons/account_tax_lock_group @@ -0,0 +1 @@ +../../../../account_tax_lock_group \ No newline at end of file diff --git a/setup/account_tax_lock_group/setup.py b/setup/account_tax_lock_group/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_tax_lock_group/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)