diff --git a/oca_dependencies.txt b/oca_dependencies.txt index ca3c726ba20d..13d6c259ce45 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1,2 @@ # See https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#oca_dependencies-txt +product-attribute https://github.com/OCA/product-attribute 14.0 diff --git a/product_multi_barcode_constraint_per_company/README.rst b/product_multi_barcode_constraint_per_company/README.rst new file mode 100644 index 000000000000..e31eb17c6333 --- /dev/null +++ b/product_multi_barcode_constraint_per_company/README.rst @@ -0,0 +1,90 @@ +====================================== +Product Barcode Constraint per Company +====================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8d6ef2af9f194f45c6e87e8557700e53e2499bf8a1f4100a37a610cd4172153a + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fstock--logistics--barcode-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-barcode/tree/14.0/product_barcode_constraint_per_company + :alt: OCA/stock-logistics-barcode +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-barcode-14-0/stock-logistics-barcode-14-0-product_barcode_constraint_per_company + :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/stock-logistics-barcode&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extend Odoo functionalities changing the constraint of the barcode +on the ``product.product`` model. + +With this module, two products can have the same barcode, if there don't belong +to the same company. + +This constraint was introduced in Odoo V9.0 in [that commit](https://github.com/odoo/odoo/commit/ede1071a09902e6eeb315cf51325a03f3991b3c3), and doesn't fit with some multi companies implementation where products are not shared. + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +Due to some limitation of the framework, this module has to add a new stored field +``tmpl_company_id`` on the ``product.product`` model related to the ``company_id`` +of the related ``product.template``. + +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 +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Sylvain LE GAL +* Sulivan Lominchar + +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/stock-logistics-barcode `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_multi_barcode_constraint_per_company/__init__.py b/product_multi_barcode_constraint_per_company/__init__.py new file mode 100644 index 000000000000..1f78e9f7bb6d --- /dev/null +++ b/product_multi_barcode_constraint_per_company/__init__.py @@ -0,0 +1,15 @@ +from . import models + +from odoo.addons.product_barcode_constraint_per_company.tests.test_module import ( + TestModule, +) +import unittest + + +@unittest.skip +def void(self): + return + + +TestModule.test_create_same_company = void +TestModule.test_create_different_company = void diff --git a/product_multi_barcode_constraint_per_company/__manifest__.py b/product_multi_barcode_constraint_per_company/__manifest__.py new file mode 100644 index 000000000000..8f90deca8b92 --- /dev/null +++ b/product_multi_barcode_constraint_per_company/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2023 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Product Multi Barcode Constraint per Company", + "version": "14.0.1.0.0", + "category": "Product", + "summary": """This is a bridge module between "product_multi_barcode" and + "product_barcode_constraint_per_company" """, + "author": "Cetmix, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-barcode", + "maintainers": ["dessanhemrayev", "CetmixGitDrone"], + "license": "AGPL-3", + "depends": [ + "product_multi_barcode", + "product_barcode_constraint_per_company", + ], + "installable": True, + "auto_install": True, +} diff --git a/product_multi_barcode_constraint_per_company/models/__init__.py b/product_multi_barcode_constraint_per_company/models/__init__.py new file mode 100644 index 000000000000..940ac3279c6a --- /dev/null +++ b/product_multi_barcode_constraint_per_company/models/__init__.py @@ -0,0 +1 @@ +from . import product_barcode diff --git a/product_multi_barcode_constraint_per_company/models/product_barcode.py b/product_multi_barcode_constraint_per_company/models/product_barcode.py new file mode 100644 index 000000000000..7c363c6ebe5e --- /dev/null +++ b/product_multi_barcode_constraint_per_company/models/product_barcode.py @@ -0,0 +1,21 @@ +# Copyright 2023 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class ProductBarcode(models.Model): + _inherit = "product.barcode" + + @api.constrains("name") + def _check_duplicates(self): + for record in self: + barcodes = self.search( + [("id", "!=", record.id), ("name", "=", record.name)], limit=1 + ) + if ( + barcodes + and barcodes.sudo().product_tmpl_id.company_id.id + == record.product_tmpl_id.company_id.id + ): + super()._check_duplicates() diff --git a/product_multi_barcode_constraint_per_company/readme/CONTRIBUTORS.rst b/product_multi_barcode_constraint_per_company/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..de3c9c1a87b5 --- /dev/null +++ b/product_multi_barcode_constraint_per_company/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Cetmix <@cetmix.com> +* Dessan Hemrayev diff --git a/product_multi_barcode_constraint_per_company/readme/DESCRIPTION.rst b/product_multi_barcode_constraint_per_company/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..3302bbef697b --- /dev/null +++ b/product_multi_barcode_constraint_per_company/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This is a bridge module between "product_barcode_constraint_per_company" and "product_multi_barcode" diff --git a/product_multi_barcode_constraint_per_company/readme/newsfragmensts/.gitkeep b/product_multi_barcode_constraint_per_company/readme/newsfragmensts/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/product_multi_barcode_constraint_per_company/static/description/icon.png b/product_multi_barcode_constraint_per_company/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/product_multi_barcode_constraint_per_company/static/description/icon.png differ diff --git a/product_multi_barcode_constraint_per_company/static/description/index.html b/product_multi_barcode_constraint_per_company/static/description/index.html new file mode 100644 index 000000000000..49b2c10c1c6b --- /dev/null +++ b/product_multi_barcode_constraint_per_company/static/description/index.html @@ -0,0 +1,433 @@ + + + + + + +Product Barcode Constraint per Company + + + +
+

Product Barcode Constraint per Company

+ + +

Beta License: AGPL-3 OCA/stock-logistics-barcode Translate me on Weblate Try me on Runboat

+

This module extend Odoo functionalities changing the constraint of the barcode +on the product.product model.

+

With this module, two products can have the same barcode, if there don’t belong +to the same company.

+

This constraint was introduced in Odoo V9.0 in [that commit](https://github.com/odoo/odoo/commit/ede1071a09902e6eeb315cf51325a03f3991b3c3), and doesn’t fit with some multi companies implementation where products are not shared.

+

Table of contents

+ +
+

Known issues / Roadmap

+

Due to some limitation of the framework, this module has to add a new stored field +tmpl_company_id on the product.product model related to the company_id +of the related product.template.

+
+
+

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

+
    +
  • GRAP
  • +
+
+
+

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/stock-logistics-barcode project on GitHub.

+

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

+
+
+
+ + diff --git a/product_multi_barcode_constraint_per_company/tests/__init__.py b/product_multi_barcode_constraint_per_company/tests/__init__.py new file mode 100644 index 000000000000..904f0e14585d --- /dev/null +++ b/product_multi_barcode_constraint_per_company/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_barcode_constraint diff --git a/product_multi_barcode_constraint_per_company/tests/test_product_barcode_constraint.py b/product_multi_barcode_constraint_per_company/tests/test_product_barcode_constraint.py new file mode 100644 index 000000000000..82693b20e074 --- /dev/null +++ b/product_multi_barcode_constraint_per_company/tests/test_product_barcode_constraint.py @@ -0,0 +1,81 @@ +# Copyright 2023 Cetmix OÜ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import types + +from psycopg2 import IntegrityError + +from odoo.tests.common import tagged +from odoo.tools.misc import mute_logger + +from odoo.addons.product_barcode_constraint_per_company.tests.test_module import ( + TestModule, +) + +from .. import void + + +@tagged("post_install", "-at_install") +class TestProductBarcodeConstraintInherit(TestModule): + def test_void(self): + """Verify the type of the result of the void method call.""" + result = void(None) + self.assertIsInstance( + result, + types.FunctionType, + msg="Expecting a FunctionType result, but got {result_type}".format( + result_type=type(result) + ), + ) + + def test_create_same_company(self): + """Verifying the Existence of a Product with the Same Barcode within a Single Company""" + # Create the first product in company_1 + product_1 = self._create_product("Product 1", self.company_1) + + # Check if the company_id of the product matches self.company_1 + self.assertEqual( + product_1.company_id, + self.company_1, + msg="Product company ID must be equal to ID #{company}".format( + company=self.company_1.id + ), + ) + + # Check if the company_id of the product_tmpl_id matches self.company_1 + self.assertEqual( + product_1.product_tmpl_id.company_id, + self.company_1, + msg="Product company ID must be equal to ID # {company}".format( + company=self.company_1.id + ), + ) + + # Try to create a second product with the same barcode in company_1 + # and expect an IntegrityError + with mute_logger("odoo.sql_db"), self.assertRaises( + IntegrityError, + msg="A barcode can only be assigned to one product per company !", + ): + self._create_product("Product 2", self.company_1) + + def test_create_different_company(self): + """Verify creating a product with the same barcode for different companies""" + # Create the first product in company_1 + product_1 = self._create_product("Product 1", self.company_1) + + # Create the second product in company_2 + product_2 = self._create_product("Product 2", self.company_2) + + # Check that the products belong to different companies + self.assertNotEqual( + product_1.company_id, + product_2.company_id, + msg="Products should belong to different companies", + ) + + # Check that the products have the same barcode + self.assertEqual( + product_1.barcode, + product_2.barcode, + msg="Products should have the same barcode", + ) diff --git a/setup/product_multi_barcode_constraint_per_company/odoo/addons/product_multi_barcode_constraint_per_company b/setup/product_multi_barcode_constraint_per_company/odoo/addons/product_multi_barcode_constraint_per_company new file mode 120000 index 000000000000..12d7d8bfa10e --- /dev/null +++ b/setup/product_multi_barcode_constraint_per_company/odoo/addons/product_multi_barcode_constraint_per_company @@ -0,0 +1 @@ +../../../../product_multi_barcode_constraint_per_company \ No newline at end of file diff --git a/setup/product_multi_barcode_constraint_per_company/setup.py b/setup/product_multi_barcode_constraint_per_company/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/product_multi_barcode_constraint_per_company/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/test-requirements.txt b/test-requirements.txt index 66bc2cbae3f9..273837fdca36 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,2 @@ odoo_test_helper +odoo14-addon-product_barcode_constraint_per_company @ git+https://github.com/OCA/stock-logistics-barcode.git@refs/pull/537/head#subdirectory=setup/product_barcode_constraint_per_company