diff --git a/README.md b/README.md index fa309b2122e..bfd8d39180a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ addon | version | maintainers | summary [base_partner_sequence](base_partner_sequence/) | 18.0.1.0.0 | | Sets customer's code from a sequence [partner_firstname](partner_firstname/) | 18.0.1.0.0 | | Split first name and last name for non company partners [partner_identification](partner_identification/) | 18.0.1.0.0 | | Partner Identification Numbers +[partner_identification_unique_by_category](partner_identification_unique_by_category/) | 18.0.1.0.0 | | Partner Identification Numbers Unique By Category [partner_pricelist_search](partner_pricelist_search/) | 18.0.1.0.0 | | Partner pricelist search [partner_ref_unique](partner_ref_unique/) | 18.0.1.0.0 | | Add an unique constraint to partner ref field [partner_tz](partner_tz/) | 18.0.1.0.0 | | Remove partner timezone default value and display on form diff --git a/partner_identification_unique_by_category/README.rst b/partner_identification_unique_by_category/README.rst new file mode 100644 index 00000000000..1e21ca2ef3d --- /dev/null +++ b/partner_identification_unique_by_category/README.rst @@ -0,0 +1,84 @@ +================================================= +Partner Identification Numbers Unique By Category +================================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5ed85dd53d73055ff809768ba6037901387c9f2eb456c5f83ef98441f180223a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/18.0/partner_identification_unique_by_category + :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-18-0/partner-contact-18-0-partner_identification_unique_by_category + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the module partner_identification to enforce having +unique id numbers by categories. This option can be set by category. + +**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 +------- + +* Camptocamp + +Contributors +------------ + +- Thierry Ducrest +- Chau Le + +Other credits +------------- + +The migration of this module from 14.0 to 18.0 was financially supported +by Camptocamp. + +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/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_identification_unique_by_category/__init__.py b/partner_identification_unique_by_category/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/partner_identification_unique_by_category/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/partner_identification_unique_by_category/__manifest__.py b/partner_identification_unique_by_category/__manifest__.py new file mode 100644 index 00000000000..d628f6dc590 --- /dev/null +++ b/partner_identification_unique_by_category/__manifest__.py @@ -0,0 +1,11 @@ +{ + "name": "Partner Identification Numbers Unique By Category", + "category": "Customer Relationship Management", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "depends": ["partner_identification"], + "data": ["views/res_partner_id_category_view.xml"], + "author": "Camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/partner-contact", + "development_status": "Production/Stable", +} diff --git a/partner_identification_unique_by_category/i18n/es.po b/partner_identification_unique_by_category/i18n/es.po new file mode 100644 index 00000000000..ff082de319e --- /dev/null +++ b/partner_identification_unique_by_category/i18n/es.po @@ -0,0 +1,77 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_identification_unique_by_category +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-13 13:33+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\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_identification_unique_by_category +#: model:ir.model.fields,field_description:partner_identification_unique_by_category.field_res_partner_id_category__has_unique_numbers +msgid "Enforce unicity" +msgstr "Reforzar la unicidad" + +#. module: partner_identification_unique_by_category +#: model:ir.model,name:partner_identification_unique_by_category.model_res_partner_id_category +msgid "Partner ID Category" +msgstr "Categoría ID de Socio" + +#. module: partner_identification_unique_by_category +#: model:ir.model,name:partner_identification_unique_by_category.model_res_partner_id_number +msgid "Partner ID Number" +msgstr "Número ID de Socio" + +#. module: partner_identification_unique_by_category +#. odoo-python +#: code:addons/partner_identification_unique_by_category/models/res_partner_id_number.py:0 +msgid "" +"The Id %(name)s in the category %(category_name)s could not be created " +"because it already exists" +msgstr "" + +#. module: partner_identification_unique_by_category +#. odoo-python +#: code:addons/partner_identification_unique_by_category/models/res_partner_id_category.py:0 +msgid "" +"The category %s can not be set to use unique numbers, because it already " +"contains duplicates." +msgstr "" + +#. module: partner_identification_unique_by_category +#: model:ir.model.fields,help:partner_identification_unique_by_category.field_res_partner_id_category__has_unique_numbers +msgid "When set, duplicate numbers will not be allowed for this category." +msgstr "" +"Si se establece, no se permitirán números duplicados para esta categoría." + +#~ msgid "Display Name" +#~ msgstr "Mostrar Nombre" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última Modificación el" + +#, python-format +#~ msgid "" +#~ "The Id {} in the category {} could not be created because it already " +#~ "exists" +#~ msgstr "El Id {} de la categoría {} no se ha podido crear porque ya existe" + +#, python-format +#~ msgid "" +#~ "The category {} can not be set to use unique numbers, because it already " +#~ "contains duplicates." +#~ msgstr "" +#~ "La categoría {} no puede configurarse para utilizar números únicos, " +#~ "porque ya contiene duplicados." diff --git a/partner_identification_unique_by_category/i18n/it.po b/partner_identification_unique_by_category/i18n/it.po new file mode 100644 index 00000000000..07e4bb850cf --- /dev/null +++ b/partner_identification_unique_by_category/i18n/it.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_identification_unique_by_category +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\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" + +#. module: partner_identification_unique_by_category +#: model:ir.model.fields,field_description:partner_identification_unique_by_category.field_res_partner_id_category__has_unique_numbers +msgid "Enforce unicity" +msgstr "" + +#. module: partner_identification_unique_by_category +#: model:ir.model,name:partner_identification_unique_by_category.model_res_partner_id_category +msgid "Partner ID Category" +msgstr "" + +#. module: partner_identification_unique_by_category +#: model:ir.model,name:partner_identification_unique_by_category.model_res_partner_id_number +msgid "Partner ID Number" +msgstr "" + +#. module: partner_identification_unique_by_category +#. odoo-python +#: code:addons/partner_identification_unique_by_category/models/res_partner_id_number.py:0 +msgid "" +"The Id %(name)s in the category %(category_name)s could not be created " +"because it already exists" +msgstr "" + +#. module: partner_identification_unique_by_category +#. odoo-python +#: code:addons/partner_identification_unique_by_category/models/res_partner_id_category.py:0 +msgid "" +"The category %s can not be set to use unique numbers, because it already " +"contains duplicates." +msgstr "" + +#. module: partner_identification_unique_by_category +#: model:ir.model.fields,help:partner_identification_unique_by_category.field_res_partner_id_category__has_unique_numbers +msgid "When set, duplicate numbers will not be allowed for this category." +msgstr "" diff --git a/partner_identification_unique_by_category/i18n/partner_identification_unique_by_category.pot b/partner_identification_unique_by_category/i18n/partner_identification_unique_by_category.pot new file mode 100644 index 00000000000..7fd7aa41b66 --- /dev/null +++ b/partner_identification_unique_by_category/i18n/partner_identification_unique_by_category.pot @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_identification_unique_by_category +# +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_identification_unique_by_category +#: model:ir.model.fields,field_description:partner_identification_unique_by_category.field_res_partner_id_category__has_unique_numbers +msgid "Enforce unicity" +msgstr "" + +#. module: partner_identification_unique_by_category +#: model:ir.model,name:partner_identification_unique_by_category.model_res_partner_id_category +msgid "Partner ID Category" +msgstr "" + +#. module: partner_identification_unique_by_category +#: model:ir.model,name:partner_identification_unique_by_category.model_res_partner_id_number +msgid "Partner ID Number" +msgstr "" + +#. module: partner_identification_unique_by_category +#. odoo-python +#: code:addons/partner_identification_unique_by_category/models/res_partner_id_number.py:0 +msgid "" +"The Id %(name)s in the category %(category_name)s could not be created " +"because it already exists" +msgstr "" + +#. module: partner_identification_unique_by_category +#. odoo-python +#: code:addons/partner_identification_unique_by_category/models/res_partner_id_category.py:0 +msgid "" +"The category %s can not be set to use unique numbers, because it already " +"contains duplicates." +msgstr "" + +#. module: partner_identification_unique_by_category +#: model:ir.model.fields,help:partner_identification_unique_by_category.field_res_partner_id_category__has_unique_numbers +msgid "When set, duplicate numbers will not be allowed for this category." +msgstr "" diff --git a/partner_identification_unique_by_category/models/__init__.py b/partner_identification_unique_by_category/models/__init__.py new file mode 100644 index 00000000000..08496db25ac --- /dev/null +++ b/partner_identification_unique_by_category/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_partner_id_number +from . import res_partner_id_category diff --git a/partner_identification_unique_by_category/models/res_partner_id_category.py b/partner_identification_unique_by_category/models/res_partner_id_category.py new file mode 100644 index 00000000000..a34a68aa1de --- /dev/null +++ b/partner_identification_unique_by_category/models/res_partner_id_category.py @@ -0,0 +1,32 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import api, fields, models +from odoo.exceptions import ValidationError + + +class ResPartnerIdCategory(models.Model): + _inherit = "res.partner.id_category" + + has_unique_numbers = fields.Boolean( + string="Enforce unicity", + help="When set, duplicate numbers will not be allowed for this category.", + ) + + @api.constrains("has_unique_numbers") + def validate_must_be_unique(self): + for rec in self: + if not rec.has_unique_numbers: + continue + ids = self.env["res.partner.id_number"].search( + [("category_id", "in", rec.ids)] + ) + unique_numbers = set(ids.mapped("name")) + if len(ids) != len(unique_numbers): + raise ValidationError( + self.env._( + "The category %s can not be set to use unique numbers, " + "because it already contains duplicates.", + rec.name, + ) + ) diff --git a/partner_identification_unique_by_category/models/res_partner_id_number.py b/partner_identification_unique_by_category/models/res_partner_id_number.py new file mode 100644 index 00000000000..4086f0a3a82 --- /dev/null +++ b/partner_identification_unique_by_category/models/res_partner_id_number.py @@ -0,0 +1,31 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import api, models +from odoo.exceptions import ValidationError + + +class ResPartnerIdNumber(models.Model): + _inherit = "res.partner.id_number" + _description = "Partner ID Number" + _order = "name" + + @api.constrains("name", "category_id") + def validate_id_number(self): + # pylint: disable=W8110 + super().validate_id_number() + for rec in self: + if not rec.category_id.has_unique_numbers: + continue + count = self.search_count( + [("name", "=", rec.name), ("category_id", "in", rec.category_id.ids)] + ) + if count > 1: + raise ValidationError( + self.env._( + "The Id %(name)s in the category %(category_name)s " + "could not be created because it already exists", + name=rec.name, + category_name=rec.category_id.name, + ) + ) diff --git a/partner_identification_unique_by_category/pyproject.toml b/partner_identification_unique_by_category/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/partner_identification_unique_by_category/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/partner_identification_unique_by_category/readme/CONTRIBUTORS.md b/partner_identification_unique_by_category/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..eced010d198 --- /dev/null +++ b/partner_identification_unique_by_category/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Thierry Ducrest \<\> +- Chau Le \<\> diff --git a/partner_identification_unique_by_category/readme/CREDITS.md b/partner_identification_unique_by_category/readme/CREDITS.md new file mode 100644 index 00000000000..573d68b7e86 --- /dev/null +++ b/partner_identification_unique_by_category/readme/CREDITS.md @@ -0,0 +1 @@ +The migration of this module from 14.0 to 18.0 was financially supported by Camptocamp. diff --git a/partner_identification_unique_by_category/readme/DESCRIPTION.md b/partner_identification_unique_by_category/readme/DESCRIPTION.md new file mode 100644 index 00000000000..df869b8a8b9 --- /dev/null +++ b/partner_identification_unique_by_category/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module extends the module partner_identification to enforce having +unique id numbers by categories. This option can be set by category. diff --git a/partner_identification_unique_by_category/static/description/icon.png b/partner_identification_unique_by_category/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/partner_identification_unique_by_category/static/description/icon.png differ diff --git a/partner_identification_unique_by_category/static/description/index.html b/partner_identification_unique_by_category/static/description/index.html new file mode 100644 index 00000000000..c1cf39c2efd --- /dev/null +++ b/partner_identification_unique_by_category/static/description/index.html @@ -0,0 +1,431 @@ + + + + + +Partner Identification Numbers Unique By Category + + + +
+

Partner Identification Numbers Unique By Category

+ + +

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

+

This module extends the module partner_identification to enforce having +unique id numbers by categories. This option can be set by category.

+

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

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 14.0 to 18.0 was financially supported +by Camptocamp.

+
+
+

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/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_identification_unique_by_category/tests/__init__.py b/partner_identification_unique_by_category/tests/__init__.py new file mode 100644 index 00000000000..ef1abf400df --- /dev/null +++ b/partner_identification_unique_by_category/tests/__init__.py @@ -0,0 +1 @@ +from . import test_partner_identification_unique_by_category diff --git a/partner_identification_unique_by_category/tests/test_partner_identification_unique_by_category.py b/partner_identification_unique_by_category/tests/test_partner_identification_unique_by_category.py new file mode 100644 index 00000000000..e5783018700 --- /dev/null +++ b/partner_identification_unique_by_category/tests/test_partner_identification_unique_by_category.py @@ -0,0 +1,84 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo.exceptions import ValidationError + +from odoo.addons.base.tests.common import BaseCommon + + +class TestPartnerIdentificationUniqueByCategory(BaseCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.category_1 = cls.env["res.partner.id_category"].create( + {"code": "UID", "name": "Group Id"} + ) + cls.category_2 = cls.env["res.partner.id_category"].create( + {"code": "GID", "name": "User Id"} + ) + cls.partner_1 = cls.env.ref("base.res_partner_1") + cls.partner_2 = cls.env.ref("base.res_partner_2") + + def test_id_creation(self): + """Check Id unique (or not) validation.""" + self.category_1.has_unique_numbers = True + self.env["res.partner.id_number"].create( + { + "name": "123", + "category_id": self.category_1.id, + "partner_id": self.partner_1.id, + } + ) + message = ( + "The Id 123 in the category Group Id could not be created " + "because it already exists" + ) + with self.assertRaisesRegex(ValidationError, message): + self.env["res.partner.id_number"].create( + { + "name": "123", + "category_id": self.category_1.id, + "partner_id": self.partner_2.id, + } + ) + # Allow to create same id in an other category + self.env["res.partner.id_number"].create( + { + "name": "123", + "category_id": self.category_2.id, + "partner_id": self.partner_2.id, + } + ) + self.category_1.has_unique_numbers = False + self.env["res.partner.id_number"].create( + { + "name": "123", + "category_id": self.category_1.id, + "partner_id": self.partner_2.id, + } + ) + + def test_category_unique_activation(self): + """Check there is no duplicate when enabling unicity.""" + self.env["res.partner.id_number"].create( + { + "name": "123456", + "category_id": self.category_1.id, + "partner_id": self.partner_1.id, + } + ) + self.category_1.has_unique_numbers = False + self.env["res.partner.id_number"].create( + { + "name": "123456", + "category_id": self.category_1.id, + "partner_id": self.partner_2.id, + } + ) + message = ( + "The category Group Id can not be set to use unique numbers, " + "because it already contains duplicates." + ) + with self.assertRaisesRegex(ValidationError, message): + self.category_1.has_unique_numbers = True diff --git a/partner_identification_unique_by_category/views/res_partner_id_category_view.xml b/partner_identification_unique_by_category/views/res_partner_id_category_view.xml new file mode 100644 index 00000000000..2860e73b2b3 --- /dev/null +++ b/partner_identification_unique_by_category/views/res_partner_id_category_view.xml @@ -0,0 +1,29 @@ + + + + res.partner.id_category.form + res.partner.id_category + + + + + + + + + res.partner.id_category.list + res.partner.id_category + + + + + + + + diff --git a/setup/_metapackage/pyproject.toml b/setup/_metapackage/pyproject.toml index 29393fc7ef1..3fd2344247b 100644 --- a/setup/_metapackage/pyproject.toml +++ b/setup/_metapackage/pyproject.toml @@ -1,11 +1,12 @@ [project] name = "odoo-addons-oca-partner-contact" -version = "18.0.20241025.2" +version = "18.0.20241027.0" dependencies = [ "odoo-addon-base_partner_company_group==18.0.*", "odoo-addon-base_partner_sequence==18.0.*", "odoo-addon-partner_firstname==18.0.*", "odoo-addon-partner_identification==18.0.*", + "odoo-addon-partner_identification_unique_by_category==18.0.*", "odoo-addon-partner_pricelist_search==18.0.*", "odoo-addon-partner_ref_unique==18.0.*", "odoo-addon-partner_tz==18.0.*",