diff --git a/contract_operating_unit/README.rst b/contract_operating_unit/README.rst new file mode 100644 index 0000000000..6b33e02f15 --- /dev/null +++ b/contract_operating_unit/README.rst @@ -0,0 +1,88 @@ +======================= +Contract Operating Unit +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e17751beb137803e478cec510202a6083afa06a957c5b53afdb71b06f1616821 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Foperating--unit-lightgray.png?logo=github + :target: https://github.com/OCA/operating-unit/tree/18.0/contract_operating_unit + :alt: OCA/operating-unit +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/operating-unit-18-0/operating-unit-18-0-contract_operating_unit + :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/operating-unit&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module introduces the following features: + +- Adds the Operating Unit (OU) to Contracts. +- Security rules are defined to ensure that users can only see the + Contracts of that Operating Units in which they are allowed access to. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Assign contracts to specific operating units within the company + +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 +------- + +* ForgeFlow S.L. + +Contributors +------------ + +- Aaron Henriquez +- Kitti U. +- Pimolnat Suntian +- Tran Thanh Trai + +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/operating-unit `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/contract_operating_unit/__init__.py b/contract_operating_unit/__init__.py new file mode 100644 index 0000000000..4b76c7b2d5 --- /dev/null +++ b/contract_operating_unit/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/contract_operating_unit/__manifest__.py b/contract_operating_unit/__manifest__.py new file mode 100644 index 0000000000..a93f7b04da --- /dev/null +++ b/contract_operating_unit/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2020 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Contract Operating Unit", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "ForgeFlow S.L., Odoo Community Association (OCA)", + "website": "https://github.com/OCA/operating-unit", + "category": "Invoicing", + "depends": ["contract", "account_operating_unit"], + "data": ["views/contract_view.xml", "security/contract_security.xml"], + "installable": True, +} diff --git a/contract_operating_unit/i18n/contract_operating_unit.pot b/contract_operating_unit/i18n/contract_operating_unit.pot new file mode 100644 index 0000000000..79817afe86 --- /dev/null +++ b/contract_operating_unit/i18n/contract_operating_unit.pot @@ -0,0 +1,25 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.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: contract_operating_unit +#: model:ir.model,name:contract_operating_unit.model_contract_contract +msgid "Contract" +msgstr "" + +#. module: contract_operating_unit +#: model:ir.model.fields,field_description:contract_operating_unit.field_contract_contract__operating_unit_id +#: model_terms:ir.ui.view,arch_db:contract_operating_unit.contract_contract_search_view +msgid "Operating Unit" +msgstr "" diff --git a/contract_operating_unit/i18n/it.po b/contract_operating_unit/i18n/it.po new file mode 100644 index 0000000000..8896072a74 --- /dev/null +++ b/contract_operating_unit/i18n/it.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-08-07 08:58+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: contract_operating_unit +#: model:ir.model,name:contract_operating_unit.model_contract_contract +msgid "Contract" +msgstr "Contratto" + +#. module: contract_operating_unit +#: model:ir.model.fields,field_description:contract_operating_unit.field_contract_contract__operating_unit_id +#: model_terms:ir.ui.view,arch_db:contract_operating_unit.contract_contract_search_view +msgid "Operating Unit" +msgstr "Unità operativa" diff --git a/contract_operating_unit/models/__init__.py b/contract_operating_unit/models/__init__.py new file mode 100644 index 0000000000..99a5468ac8 --- /dev/null +++ b/contract_operating_unit/models/__init__.py @@ -0,0 +1 @@ +from . import contract diff --git a/contract_operating_unit/models/contract.py b/contract_operating_unit/models/contract.py new file mode 100644 index 0000000000..1147f91f32 --- /dev/null +++ b/contract_operating_unit/models/contract.py @@ -0,0 +1,22 @@ +# Copyright 2020 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ContractContract(models.Model): + _inherit = "contract.contract" + + operating_unit_id = fields.Many2one( + "operating.unit", + "Operating Unit", + default=lambda self: self.env["res.users"]._get_default_operating_unit( + self._uid + ), + ) + + def _prepare_invoice(self, date_invoice, journal=None): + invoice_vals = super()._prepare_invoice(date_invoice, journal=journal) + if self.operating_unit_id: + invoice_vals["operating_unit_id"] = self.operating_unit_id.id + return invoice_vals diff --git a/contract_operating_unit/pyproject.toml b/contract_operating_unit/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/contract_operating_unit/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/contract_operating_unit/readme/CONTRIBUTORS.md b/contract_operating_unit/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..d57bfc9948 --- /dev/null +++ b/contract_operating_unit/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Aaron Henriquez \<\> +- Kitti U. \<\> +- Pimolnat Suntian \<\> +- Tran Thanh Trai \<\> diff --git a/contract_operating_unit/readme/DESCRIPTION.md b/contract_operating_unit/readme/DESCRIPTION.md new file mode 100644 index 0000000000..dd363ee60b --- /dev/null +++ b/contract_operating_unit/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module introduces the following features: + +- Adds the Operating Unit (OU) to Contracts. +- Security rules are defined to ensure that users can only see the + Contracts of that Operating Units in which they are allowed access to. diff --git a/contract_operating_unit/readme/USAGE.md b/contract_operating_unit/readme/USAGE.md new file mode 100644 index 0000000000..f4c95c254e --- /dev/null +++ b/contract_operating_unit/readme/USAGE.md @@ -0,0 +1 @@ +Assign contracts to specific operating units within the company diff --git a/contract_operating_unit/security/contract_security.xml b/contract_operating_unit/security/contract_security.xml new file mode 100644 index 0000000000..089d7fdcaa --- /dev/null +++ b/contract_operating_unit/security/contract_security.xml @@ -0,0 +1,15 @@ + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',operating_unit_ids)] + Contracts from allowed operating units + + + + + + + diff --git a/contract_operating_unit/static/description/icon.png b/contract_operating_unit/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/contract_operating_unit/static/description/icon.png differ diff --git a/contract_operating_unit/static/description/index.html b/contract_operating_unit/static/description/index.html new file mode 100644 index 0000000000..28fd270c9f --- /dev/null +++ b/contract_operating_unit/static/description/index.html @@ -0,0 +1,436 @@ + + + + + +Contract Operating Unit + + + +
+

Contract Operating Unit

+ + +

Beta License: AGPL-3 OCA/operating-unit Translate me on Weblate Try me on Runboat

+

This module introduces the following features:

+
    +
  • Adds the Operating Unit (OU) to Contracts.
  • +
  • Security rules are defined to ensure that users can only see the +Contracts of that Operating Units in which they are allowed access to.
  • +
+

Table of contents

+ +
+

Usage

+

Assign contracts to specific operating units within the company

+
+
+

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

+
    +
  • ForgeFlow S.L.
  • +
+
+
+

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/operating-unit project on GitHub.

+

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

+
+
+
+ + diff --git a/contract_operating_unit/tests/__init__.py b/contract_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..fdd2b1a354 --- /dev/null +++ b/contract_operating_unit/tests/__init__.py @@ -0,0 +1 @@ +from . import test_contract_operating_unit diff --git a/contract_operating_unit/tests/test_contract_operating_unit.py b/contract_operating_unit/tests/test_contract_operating_unit.py new file mode 100644 index 0000000000..23f6fd5dc5 --- /dev/null +++ b/contract_operating_unit/tests/test_contract_operating_unit.py @@ -0,0 +1,92 @@ +# Copyright 2020 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.addons.contract.tests.test_contract import TestContractBase + + +class TestContractOperatingUnit(TestContractBase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + cls.res_users_model = cls.env["res.users"] + + cls.company = cls.env.ref("base.main_company") + cls.grp_contract_manager = cls.env.ref("account.group_account_manager") + cls.contract_model = cls.env["contract.contract"] + cls.group_user = cls.env.ref("base.group_user") + + # Main Operating Unit + cls.ou1 = cls.env.ref("operating_unit.main_operating_unit") + # B2C Operating Unit + cls.b2c = cls.env.ref("operating_unit.b2c_operating_unit") + + # Create Users + cls.user1 = cls._create_user( + "User_1", + [cls.grp_contract_manager, cls.group_user], + cls.company, + [cls.ou1, cls.b2c], + ) + cls.user2 = cls._create_user( + "User_2", + [cls.grp_contract_manager, cls.group_user], + cls.company, + [cls.b2c], + ) + cls.contract.operating_unit_id = cls.ou1 + cls.contract2.operating_unit_id = cls.b2c + + @classmethod + def _create_user(cls, login, groups, company, operating_units, context=None): + """Creates a user.""" + group_ids = [group.id for group in groups] + user = cls.res_users_model.create( + { + "name": "Test Contract User", + "login": login, + "password": "demo", + "email": "example@yourcompany.com", + "company_id": company.id, + "company_ids": [(4, company.id)], + "operating_unit_ids": [(4, ou.id) for ou in operating_units], + "groups_id": [(6, 0, group_ids)], + } + ) + return user + + def test_contract_ou(self): + """Test Contract Operating Unit""" + # User 2 is only assigned to Operating Unit B2C, and cannot + # Access Contract records of Main Operating Unit. + record = self.contract_model.with_user(self.user2.id).search( + [ + ("id", "=", self.contract.id), + ("operating_unit_id", "=", self.ou1.id), + ] + ) + self.assertFalse( + record, + f"User 2 should not have access to OU {self.ou1.name}", + ) + + def test_default(self): + """Test that the user's OU is used when creating a contract""" + contract = ( + self.env["contract.contract"] + .with_user(self.user1) + .create( + { + "name": "A contract", + "partner_id": self.env["res.partner"] + .search([], order="customer_rank desc", limit=1) + .id, + } + ) + ) + self.assertEqual(contract.operating_unit_id, self.ou1) + + def test_contract_invoice(self): + """Test that invoices from contracts get the contract's OU assigned""" + invoice = self.contract2._recurring_create_invoice() + self.assertEqual(invoice.operating_unit_id, self.b2c) diff --git a/contract_operating_unit/views/contract_view.xml b/contract_operating_unit/views/contract_view.xml new file mode 100644 index 0000000000..34dbe19680 --- /dev/null +++ b/contract_operating_unit/views/contract_view.xml @@ -0,0 +1,78 @@ + + + + + contract.contract form view (in contract_payment_mode) + contract.contract + + + + + + + + + + + contract.contract list view (in contract_payment_mode) + contract.contract + + + + + + + + + + + contract.contract search view (in contract_payment_mode) + contract.contract + + + + + + + + + + + + + + contract.contract supplier form view (in contract_payment_mode) + contract.contract + 18 + + + + + + + +