diff --git a/partner_category_type/README.rst b/partner_category_type/README.rst new file mode 100644 index 00000000000..ae93932da5f --- /dev/null +++ b/partner_category_type/README.rst @@ -0,0 +1,94 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +===================== +Partner Category Type +===================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:801755c18a8f3457926274b02ee6e7d6d5523fc167a7bde412fbdd7843addc4e + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/19.0/partner_category_type + :alt: OCA/partner-contact +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/partner-contact-19-0/partner-contact-19-0-partner_category_type + :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/partner-contact&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a selection field 'Type' in Contact Tags to be +inherited and used in other modules. + +**Table of contents** + +.. contents:: + :local: + +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 + +Contributors +------------ + +- Jordi Masvidal +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +- Hudson Amadeus Leonardy (https://solusiaglis.co.id) + +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-JordiMForgeFlow| image:: https://github.com/JordiMForgeFlow.png?size=40px + :target: https://github.com/JordiMForgeFlow + :alt: JordiMForgeFlow + +Current `maintainer `__: + +|maintainer-JordiMForgeFlow| + +This module is part of the `OCA/partner-contact `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_category_type/__init__.py b/partner_category_type/__init__.py new file mode 100644 index 00000000000..4b76c7b2d5c --- /dev/null +++ b/partner_category_type/__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/partner_category_type/__manifest__.py b/partner_category_type/__manifest__.py new file mode 100644 index 00000000000..4753420b22f --- /dev/null +++ b/partner_category_type/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2023 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Partner Category Type", + "summary": "Add a selection field 'Type' to classify Contact Tags.", + "version": "19.0.1.0.0", + "category": "Partner Management", + "website": "https://github.com/OCA/partner-contact", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "maintainers": ["JordiMForgeFlow"], + "depends": ["contacts"], + "data": ["views/res_partner_category_views.xml"], +} diff --git a/partner_category_type/i18n/it.po b/partner_category_type/i18n/it.po new file mode 100644 index 00000000000..1d2fd0a10bc --- /dev/null +++ b/partner_category_type/i18n/it.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_category_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-27 11:42+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 4.17\n" + +#. module: partner_category_type +#. odoo-python +#: code:addons/partner_category_type/models/res_partner_category.py:0 +#, python-format +msgid "" +"Contact Tag '%(tag_name)s' has different type than parent '%(parent_name)s'." +msgstr "" +"Il contatto etichetta '%(tag_name)s' ha un tipo diverso dal parent " +"'%(parent_name)s'." + +#. module: partner_category_type +#. odoo-python +#: code:addons/partner_category_type/models/res_partner_category.py:0 +#, python-format +msgid "Generic" +msgstr "Generico" + +#. module: partner_category_type +#: model:ir.model,name:partner_category_type.model_res_partner_category +msgid "Partner Tags" +msgstr "Etichette partner" + +#. module: partner_category_type +#: model:ir.model.fields,field_description:partner_category_type.field_res_partner_category__category_type +msgid "Type" +msgstr "Tipo" diff --git a/partner_category_type/i18n/partner_category_type.pot b/partner_category_type/i18n/partner_category_type.pot new file mode 100644 index 00000000000..d2e6cf5d52d --- /dev/null +++ b/partner_category_type/i18n/partner_category_type.pot @@ -0,0 +1,37 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_category_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.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: partner_category_type +#. odoo-python +#: code:addons/partner_category_type/models/res_partner_category.py:0 +msgid "" +"Contact Tag '%(tag_name)s' has different type than parent '%(parent_name)s'." +msgstr "" + +#. module: partner_category_type +#. odoo-python +#: code:addons/partner_category_type/models/res_partner_category.py:0 +msgid "Generic" +msgstr "" + +#. module: partner_category_type +#: model:ir.model,name:partner_category_type.model_res_partner_category +msgid "Partner Tags" +msgstr "" + +#. module: partner_category_type +#: model:ir.model.fields,field_description:partner_category_type.field_res_partner_category__category_type +msgid "Type" +msgstr "" diff --git a/partner_category_type/models/__init__.py b/partner_category_type/models/__init__.py new file mode 100644 index 00000000000..36e14ba4704 --- /dev/null +++ b/partner_category_type/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import res_partner_category diff --git a/partner_category_type/models/res_partner_category.py b/partner_category_type/models/res_partner_category.py new file mode 100644 index 00000000000..0a785e2ea03 --- /dev/null +++ b/partner_category_type/models/res_partner_category.py @@ -0,0 +1,52 @@ +# Copyright 2023 ForgeFlow, S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models +from odoo.exceptions import ValidationError + + +class ResPartnerCategory(models.Model): + _inherit = "res.partner.category" + + def _get_category_type_selection(self): + return [("generic", self.env._("Generic"))] + + def _get_default_category_type(self): + return "generic" + + category_type = fields.Selection( + string="Type", + selection="_get_category_type_selection", + required=True, + default=_get_default_category_type, + compute="_compute_category_type", + inverse="_inverse_category_type", + store=True, + ) + + @api.constrains("parent_id", "category_type") + def _check_parent_type(self): + for rec in self: + if rec.parent_id and rec.parent_id.category_type != rec.category_type: + raise ValidationError( + self.env._( + "Contact Tag '%(tag_name)s' has different type than " + "parent '%(parent_name)s'.", + tag_name=rec.name, + parent_name=rec.parent_id.name, + ) + ) + + @api.depends("parent_id") + def _compute_category_type(self): + default_category = self._get_default_category_type() + for rec in self: + if rec.parent_id: + rec.category_type = rec.parent_id.category_type + else: + rec.category_type = default_category + + def _inverse_category_type(self): + for rec in self: + if rec.child_ids: + rec.child_ids.write({"category_type": rec.category_type}) diff --git a/partner_category_type/pyproject.toml b/partner_category_type/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/partner_category_type/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/partner_category_type/readme/CONTRIBUTORS.md b/partner_category_type/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..ee71ac89cc0 --- /dev/null +++ b/partner_category_type/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Jordi Masvidal \<\> +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia +- Hudson Amadeus Leonardy (https://solusiaglis.co.id) \ No newline at end of file diff --git a/partner_category_type/readme/DESCRIPTION.md b/partner_category_type/readme/DESCRIPTION.md new file mode 100644 index 00000000000..de2af48b589 --- /dev/null +++ b/partner_category_type/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module adds a selection field 'Type' in Contact Tags to be +inherited and used in other modules. diff --git a/partner_category_type/static/description/icon.png b/partner_category_type/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/partner_category_type/static/description/icon.png differ diff --git a/partner_category_type/static/description/index.html b/partner_category_type/static/description/index.html new file mode 100644 index 00000000000..b33724beec0 --- /dev/null +++ b/partner_category_type/static/description/index.html @@ -0,0 +1,437 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Partner Category Type

+ +

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runboat

+

This module adds a selection field ‘Type’ in Contact Tags to be +inherited and used in other modules.

+

Table of contents

+ +
+

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
  • +
+
+
+

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:

+

JordiMForgeFlow

+

This module is part of the OCA/partner-contact project on GitHub.

+

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

+
+
+
+
+ + diff --git a/partner_category_type/tests/__init__.py b/partner_category_type/tests/__init__.py new file mode 100644 index 00000000000..9eda560c2a5 --- /dev/null +++ b/partner_category_type/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2023 ForgeFlow, S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import test_partner_category_type diff --git a/partner_category_type/tests/test_partner_category_type.py b/partner_category_type/tests/test_partner_category_type.py new file mode 100644 index 00000000000..3c1a8831680 --- /dev/null +++ b/partner_category_type/tests/test_partner_category_type.py @@ -0,0 +1,117 @@ +# Copyright 2023 ForgeFlow, S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.exceptions import ValidationError + +from odoo.addons.base.tests.common import BaseCommon + + +class TestResPartnerCategory(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Create base test categories + cls.category_parent = cls.env["res.partner.category"].create( + { + "name": "Parent Category", + } + ) + cls.category_child = cls.env["res.partner.category"].create( + { + "name": "Child Category", + "parent_id": cls.category_parent.id, + } + ) + + def test_01_default_category_type(self): + """Test that new categories get the default generic type""" + category_model = self.env["res.partner.category"] + default_type = category_model._get_default_category_type() + self.assertEqual(default_type, "generic") + + new_category = category_model.create( + { + "name": "Test Category", + } + ) + self.assertEqual(new_category.category_type, "generic") + + def test_02_parent_child_category_type(self): + """Test that child categories inherit parent's type""" + # Change parent category type + self.category_parent.category_type = "generic" + # Check that child category inherits the type + self.assertEqual(self.category_child.category_type, "generic") + + def test_03_category_type_constraint(self): + """Test constraint preventing different types between parent and child""" + with self.assertRaises(ValidationError): + self.category_parent.category_type = "generic" + self.env["res.partner.category"].create( + { + "name": "Invalid Child Category", + "parent_id": self.category_parent.id, + "category_type": "test", # Different from parent's 'generic' type + } + ) + + def test_04_change_parent_category_type(self): + """Test that changing parent category type updates all children""" + parent = self.env["res.partner.category"].create({"name": "Parent"}) + child1 = self.env["res.partner.category"].create( + {"name": "Child 1", "parent_id": parent.id} + ) + child2 = self.env["res.partner.category"].create( + {"name": "Child 2", "parent_id": child1.id} + ) + + def extended_selection(self): + return [("generic", "Generic"), ("test", "Test")] + + original_selection = type(parent)._get_category_type_selection + + try: + type(parent)._get_category_type_selection = extended_selection + parent.category_type = "test" + self.assertEqual(child1.category_type, "test") + self.assertEqual(child2.category_type, "test") + finally: + type( + parent + )._get_category_type_selection = ( + original_selection # Ensure this always runs + ) + + def test_05_compute_category_type(self): + """Test computation of category type based on parent""" + # Create standalone category + standalone = self.env["res.partner.category"].create( + { + "name": "Standalone", + } + ) + + # Verify it gets default type + self.assertEqual(standalone.category_type, "generic") + + # Set as child of existing category + standalone.parent_id = self.category_parent.id + + # Verify type is inherited from parent + self.assertEqual(standalone.category_type, self.category_parent.category_type) + + # Remove parent to test default category assignment + standalone.parent_id = False + + # Force recompute of category_type + standalone.invalidate_recordset(["category_type"]) + standalone._compute_category_type() + + # Verify it returns to default category type + self.assertEqual(standalone.category_type, "generic") + + def test_06_get_category_type_selection(self): + """Test _get_category_type_selection method""" + category_model = self.env["res.partner.category"] + selection = category_model._get_category_type_selection() + self.assertIn(("generic", "Generic"), selection) diff --git a/partner_category_type/views/res_partner_category_views.xml b/partner_category_type/views/res_partner_category_views.xml new file mode 100644 index 00000000000..ea5d60cad75 --- /dev/null +++ b/partner_category_type/views/res_partner_category_views.xml @@ -0,0 +1,24 @@ + + + + res.partner.category.tree - partner_category_type + res.partner.category + + + + + + + + + + res.partner.category.form - partner_category_type + res.partner.category + + + + + + + +