diff --git a/account_account_constraint_code/README.rst b/account_account_constraint_code/README.rst new file mode 100644 index 000000000..bf1176cf1 --- /dev/null +++ b/account_account_constraint_code/README.rst @@ -0,0 +1,75 @@ +=============================== +Account Account Constraint Code +=============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/account_account_lock_code/account_account_constraint_code + :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-account_account_lock_code/account_financial_tools-account_account_lock_code-account_account_constraint_code + :alt: Translate me on Weblate + +|badge1| |badge2| |badge3| |badge4| + +Disable account's code modification when you have journal items for this account + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +No configuation needed, effective after install + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Xavier Bouquiaux + +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. + +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_account_constraint_code/__init__.py b/account_account_constraint_code/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/account_account_constraint_code/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_account_constraint_code/__manifest__.py b/account_account_constraint_code/__manifest__.py new file mode 100644 index 000000000..09d77101d --- /dev/null +++ b/account_account_constraint_code/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Account Account Constraint Code", + "summary": "Forbid modification of code when account move line linked to the account", + "version": "14.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"], + "demo": [], +} diff --git a/account_account_constraint_code/models/__init__.py b/account_account_constraint_code/models/__init__.py new file mode 100644 index 000000000..5a5ba4f99 --- /dev/null +++ b/account_account_constraint_code/models/__init__.py @@ -0,0 +1 @@ +from . import account_account diff --git a/account_account_constraint_code/models/account_account.py b/account_account_constraint_code/models/account_account.py new file mode 100644 index 000000000..7dc631308 --- /dev/null +++ b/account_account_constraint_code/models/account_account.py @@ -0,0 +1,22 @@ +# Copyright 2022 ACSONE SA/NV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class AccountAccount(models.Model): + + _inherit = "account.account" + + @api.constrains("code") + def _disable_code_modification(self): + line = ( + self.env["account.move.line"] + .sudo() + .search([("account_id", "in", self.ids)], limit=1) + ) + if line: + raise ValidationError( + _("You cannot change the code of account which contains journal items.") + ) diff --git a/account_account_constraint_code/readme/CONFIGURE.rst b/account_account_constraint_code/readme/CONFIGURE.rst new file mode 100644 index 000000000..7081daeb0 --- /dev/null +++ b/account_account_constraint_code/readme/CONFIGURE.rst @@ -0,0 +1 @@ +No configuation needed, effective after install diff --git a/account_account_constraint_code/readme/CONTRIBUTORS.rst b/account_account_constraint_code/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..90c1a5060 --- /dev/null +++ b/account_account_constraint_code/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Xavier Bouquiaux diff --git a/account_account_constraint_code/readme/DESCRIPTION.rst b/account_account_constraint_code/readme/DESCRIPTION.rst new file mode 100644 index 000000000..01c30f037 --- /dev/null +++ b/account_account_constraint_code/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Disallow the modification of the code of accounts that have journal items. diff --git a/account_account_constraint_code/static/description/index.html b/account_account_constraint_code/static/description/index.html new file mode 100644 index 000000000..553a7d584 --- /dev/null +++ b/account_account_constraint_code/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +Account Account Constraint Code + + + +
+

Account Account Constraint Code

+ + +

Beta License: AGPL-3 OCA/account_financial_tools Translate me on Weblate

+

Disable account’s code modification when you have journal items for this account

+

Table of contents

+ +
+

Configuration

+

No configuation needed, effective after install

+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

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.

+

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_account_constraint_code/tests/__init__.py b/account_account_constraint_code/tests/__init__.py new file mode 100644 index 000000000..0c856c5df --- /dev/null +++ b/account_account_constraint_code/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_account diff --git a/account_account_constraint_code/tests/test_account_account.py b/account_account_constraint_code/tests/test_account_account.py new file mode 100644 index 000000000..deba2744e --- /dev/null +++ b/account_account_constraint_code/tests/test_account_account.py @@ -0,0 +1,55 @@ +# Copyright 2022 Acsone SA (http://www.acsone.eu/) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo import fields +from odoo.exceptions import ValidationError +from odoo.tests.common import SavepointCase + + +class TestAccountAccount(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.misc_journal = cls.env["account.journal"].create( + { + "name": "Test Journal Move name seq", + "code": "ADLM", + "type": "general", + "company_id": cls.env.company.id, + } + ) + cls.accounts = cls.env["account.account"].search( + [("company_id", "=", cls.env.company.id)], limit=2 + ) + cls.account1 = cls.accounts[0] + cls.account2 = cls.accounts[1] + cls.date = fields.Datetime.now() + + def test_constraint_code(self): + + self.account1.write({"code": 123456}) + move = self.env["account.move"].create( + { + "date": self.date, + "journal_id": self.misc_journal.id, + "line_ids": [ + (0, 0, {"account_id": self.account1.id, "debit": 10}), + (0, 0, {"account_id": self.account2.id, "credit": 10}), + ], + } + ) + with self.assertRaises(ValidationError) as ve: + self.account1.write({"code": 123789}) + self.assertIn( + "You cannot change the code of account which contains journal items.", + ve.exception.args[0], + ) + move.action_post() + with self.assertRaises(ValidationError) as ve: + self.account1.write({"code": 654321}) + self.assertIn( + "You cannot change the code of account which contains journal items.", + ve.exception.args[0], + ) diff --git a/setup/account_account_constraint_code/odoo/addons/account_account_constraint_code b/setup/account_account_constraint_code/odoo/addons/account_account_constraint_code new file mode 120000 index 000000000..72722556c --- /dev/null +++ b/setup/account_account_constraint_code/odoo/addons/account_account_constraint_code @@ -0,0 +1 @@ +../../../../account_account_constraint_code \ No newline at end of file diff --git a/setup/account_account_constraint_code/setup.py b/setup/account_account_constraint_code/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_account_constraint_code/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)