diff --git a/account_payment_term_security/README.rst b/account_payment_term_security/README.rst new file mode 100644 index 00000000000..c821116cb16 --- /dev/null +++ b/account_payment_term_security/README.rst @@ -0,0 +1,96 @@ +===================== +Payment Term Security +===================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f4300bd16646870003a5be64e2e4484acee9b46b4e2e2b9d442ad43a06a7f801 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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--payment-lightgray.png?logo=github + :target: https://github.com/OCA/account-payment/tree/17.0/account_payment_term_security + :alt: OCA/account-payment +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-payment-17-0/account-payment-17-0-account_payment_term_security + :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-payment&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +In partners and invoices, payment terms can only be changed when the +user has permission "Change payment terms in partners and invoices". + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To use this module, you need to : + +Go to Settings > Users & Companies > Users (edit your user) > Set +"Change payment terms in partners and invoices" option. + +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 +------- + +* Tecnativa + +Contributors +------------ + +- \`Tecnativa \`: + + - Pedro M. Baeza + - Víctor Martínez + +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-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/account-payment `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_term_security/__init__.py b/account_payment_term_security/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/account_payment_term_security/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/account_payment_term_security/__manifest__.py b/account_payment_term_security/__manifest__.py new file mode 100644 index 00000000000..d37b08ba299 --- /dev/null +++ b/account_payment_term_security/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2023 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Payment Term Security", + "version": "17.0.1.0.0", + "category": "Accounting & Finance", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainer": "OCA", + "website": "https://github.com/OCA/account-payment", + "license": "AGPL-3", + "depends": ["account"], + "data": ["security/security.xml"], + "installable": True, + "maintainers": ["victoralmau"], +} diff --git a/account_payment_term_security/i18n/account_payment_term_security.pot b/account_payment_term_security/i18n/account_payment_term_security.pot new file mode 100644 index 00000000000..34b4c29bc6b --- /dev/null +++ b/account_payment_term_security/i18n/account_payment_term_security.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_term_security +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \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_payment_term_security +#: model:res.groups,name:account_payment_term_security.account_payment_term_mgmt +msgid "Change payment terms in partners and invoices" +msgstr "" + +#. module: account_payment_term_security +#: model:ir.model,name:account_payment_term_security.model_res_partner +msgid "Contact" +msgstr "" + +#. module: account_payment_term_security +#: model:ir.model,name:account_payment_term_security.model_account_move +msgid "Journal Entry" +msgstr "" diff --git a/account_payment_term_security/i18n/es.po b/account_payment_term_security/i18n/es.po new file mode 100644 index 00000000000..758d4500edb --- /dev/null +++ b/account_payment_term_security/i18n/es.po @@ -0,0 +1,33 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_payment_term_security +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2023-09-21 16:38+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: account_payment_term_security +#: model:res.groups,name:account_payment_term_security.account_payment_term_mgmt +msgid "Change payment terms in partners and invoices" +msgstr "Cambiar plazos de pago en contactos y facturas" + +#. module: account_payment_term_security +#: model:ir.model,name:account_payment_term_security.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: account_payment_term_security +#: model:ir.model,name:account_payment_term_security.model_account_move +msgid "Journal Entry" +msgstr "Entrada Diaria" diff --git a/account_payment_term_security/models/__init__.py b/account_payment_term_security/models/__init__.py new file mode 100644 index 00000000000..74548553bd8 --- /dev/null +++ b/account_payment_term_security/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_move +from . import res_partner diff --git a/account_payment_term_security/models/account_move.py b/account_payment_term_security/models/account_move.py new file mode 100644 index 00000000000..01557364e10 --- /dev/null +++ b/account_payment_term_security/models/account_move.py @@ -0,0 +1,22 @@ +# Copyright 2023-2025 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from lxml import etree + +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.model + def get_view(self, view_id=None, view_type="form", **options): + result = super().get_view(view_id=view_id, view_type=view_type, **options) + group = "account_payment_term_security.account_payment_term_mgmt" + if view_type == "form" and not self.env.user.has_group(group): + doc = etree.XML(result["arch"]) + for node in doc.xpath("//field[@name='invoice_payment_term_id']"): + node.set("readonly", "1") + node.set("force_save", "1") + result["arch"] = etree.tostring(doc, encoding="unicode") + return result diff --git a/account_payment_term_security/models/res_partner.py b/account_payment_term_security/models/res_partner.py new file mode 100644 index 00000000000..a05dfbdc831 --- /dev/null +++ b/account_payment_term_security/models/res_partner.py @@ -0,0 +1,25 @@ +# Copyright 2023.2025 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from lxml import etree + +from odoo import api, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + @api.model + def get_view(self, view_id=None, view_type="form", **options): + result = super().get_view(view_id=view_id, view_type=view_type, **options) + group = "account_payment_term_security.account_payment_term_mgmt" + if view_type == "form" and not self.env.user.has_group(group): + doc = etree.XML(result["arch"]) + for node in doc.xpath("//field[@name='property_payment_term_id']"): + node.set("readonly", "1") + node.set("force_save", "1") + for node in doc.xpath("//field[@name='property_supplier_payment_term_id']"): + node.set("readonly", "1") + node.set("force_save", "1") + result["arch"] = etree.tostring(doc, encoding="unicode") + return result diff --git a/account_payment_term_security/pyproject.toml b/account_payment_term_security/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/account_payment_term_security/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/account_payment_term_security/readme/CONFIGURE.md b/account_payment_term_security/readme/CONFIGURE.md new file mode 100644 index 00000000000..70b13768f49 --- /dev/null +++ b/account_payment_term_security/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +To use this module, you need to : + +Go to Settings \> Users & Companies \> Users (edit your user) \> Set +"Change payment terms in partners and invoices" option. diff --git a/account_payment_term_security/readme/CONTRIBUTORS.md b/account_payment_term_security/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..dab408a70b2 --- /dev/null +++ b/account_payment_term_security/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- \`Tecnativa \<\>\`: + - Pedro M. Baeza + - Víctor Martínez diff --git a/account_payment_term_security/readme/DESCRIPTION.md b/account_payment_term_security/readme/DESCRIPTION.md new file mode 100644 index 00000000000..6af712271d8 --- /dev/null +++ b/account_payment_term_security/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +In partners and invoices, payment terms can only be changed when the +user has permission "Change payment terms in partners and invoices". diff --git a/account_payment_term_security/security/security.xml b/account_payment_term_security/security/security.xml new file mode 100644 index 00000000000..3e542b55681 --- /dev/null +++ b/account_payment_term_security/security/security.xml @@ -0,0 +1,12 @@ + + + + Change payment terms in partners and invoices + + + + + diff --git a/account_payment_term_security/static/description/icon.png b/account_payment_term_security/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/account_payment_term_security/static/description/icon.png differ diff --git a/account_payment_term_security/static/description/index.html b/account_payment_term_security/static/description/index.html new file mode 100644 index 00000000000..b8908a8282e --- /dev/null +++ b/account_payment_term_security/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +Payment Term Security + + + +
+

Payment Term Security

+ + +

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

+

In partners and invoices, payment terms can only be changed when the +user has permission “Change payment terms in partners and invoices”.

+

Table of contents

+ +
+

Configuration

+

To use this module, you need to :

+

Go to Settings > Users & Companies > Users (edit your user) > Set +“Change payment terms in partners and invoices” option.

+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

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:

+

victoralmau

+

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

+

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

+
+
+
+ + diff --git a/account_payment_term_security/tests/__init__.py b/account_payment_term_security/tests/__init__.py new file mode 100644 index 00000000000..37bdc827531 --- /dev/null +++ b/account_payment_term_security/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_account_payment_term_security diff --git a/account_payment_term_security/tests/test_account_payment_term_security.py b/account_payment_term_security/tests/test_account_payment_term_security.py new file mode 100644 index 00000000000..6af75495642 --- /dev/null +++ b/account_payment_term_security/tests/test_account_payment_term_security.py @@ -0,0 +1,71 @@ +# Copyright 2023-2025 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from lxml import etree + +from odoo.tests import new_test_user, users + +from odoo.addons.base.tests.common import BaseCommon + + +class TestAccountPaymentTermSecurity(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + account_group = "account.group_account_invoice" + new_test_user( + cls.env, + login="test-account-user", + groups=account_group, + ) + payment_term_group = "account_payment_term_security.account_payment_term_mgmt" + new_test_user( + cls.env, + login="test-acount-payment_term_mgmt-user", + groups=f"{account_group},{payment_term_group}", + ) + + @users("test-account-user") + def test_res_partner_01(self): + view = self.env["res.partner"].get_view() + doc = etree.XML(view["arch"]) + field_payment_term_id = doc.xpath("//field[@name='property_payment_term_id']")[ + 0 + ] + self.assertTrue(field_payment_term_id.attrib["readonly"]) + self.assertTrue(field_payment_term_id.attrib["force_save"]) + field_payment_term_id = doc.xpath( + "//field[@name='property_supplier_payment_term_id']" + )[0] + self.assertTrue(field_payment_term_id.attrib["readonly"]) + self.assertTrue(field_payment_term_id.attrib["force_save"]) + + @users("test-acount-payment_term_mgmt-user") + def test_res_partner_02(self): + view = self.env["res.partner"].get_view() + doc = etree.XML(view["arch"]) + field_payment_term_id = doc.xpath("//field[@name='property_payment_term_id']")[ + 0 + ] + self.assertNotIn("readonly", field_payment_term_id.attrib) + self.assertNotIn("force_save", field_payment_term_id.attrib) + field_payment_term_id = doc.xpath( + "//field[@name='property_supplier_payment_term_id']" + )[0] + self.assertNotIn("readonly", field_payment_term_id.attrib) + self.assertNotIn("force_save", field_payment_term_id.attrib) + + @users("test-account-user") + def test_account_move_01(self): + view = self.env["account.move"].get_view() + doc = etree.XML(view["arch"]) + field_payment_term_id = doc.xpath("//field[@name='invoice_payment_term_id']")[0] + self.assertTrue(field_payment_term_id.attrib["readonly"]) + self.assertTrue(field_payment_term_id.attrib["force_save"]) + + @users("test-acount-payment_term_mgmt-user") + def test_account_move_02(self): + view = self.env["account.move"].get_view() + doc = etree.XML(view["arch"]) + field_payment_term_id = doc.xpath("//field[@name='invoice_payment_term_id']")[0] + self.assertNotEqual(field_payment_term_id.attrib["readonly"], "1") + self.assertNotIn("force_save", field_payment_term_id.attrib)