From 6cc4f181d8413ef14b7f9987131950e5dc20fd79 Mon Sep 17 00:00:00 2001 From: dessanhemrayev Date: Sun, 29 Oct 2023 12:43:09 +0300 Subject: [PATCH] [IMP] product_barcode_constraint_per_company Simplify logic --- .../__manifest__.py | 7 ++--- .../models/product_product.py | 26 +++++++------------ .../readme/CONTRIBUTORS.rst | 2 ++ .../tests/test_module.py | 4 --- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/product_barcode_constraint_per_company/__manifest__.py b/product_barcode_constraint_per_company/__manifest__.py index 2fef2fe50b1b..d2f68785f8c1 100644 --- a/product_barcode_constraint_per_company/__manifest__.py +++ b/product_barcode_constraint_per_company/__manifest__.py @@ -1,18 +1,19 @@ +# Copyright 2023 Cetmix OÜ # Copyright (C) 2020-Today: GRAP (http://www.grap.coop) # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Product Barcode Constraint per Company", - "version": "14.0.1.0.1", + "version": "14.0.2.0.0", "category": "Product", "summary": "Change the product barcode constraint" ", allowing the same barcode for differents companies", - "author": "GRAP, Odoo Community Association (OCA)", + "author": "GRAP, Cetmix, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-barcode", "license": "AGPL-3", "depends": [ - "product", + "product_variant_company", ], "installable": True, } diff --git a/product_barcode_constraint_per_company/models/product_product.py b/product_barcode_constraint_per_company/models/product_product.py index 3a6591366c4e..e364a8f7860f 100644 --- a/product_barcode_constraint_per_company/models/product_product.py +++ b/product_barcode_constraint_per_company/models/product_product.py @@ -1,25 +1,19 @@ +# Copyright 2023 Cetmix OÜ # Copyright (C) 2020-Today: GRAP (http://www.grap.coop) # @author: Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import _, fields, models +from odoo import _, models class ProductProduct(models.Model): _inherit = "product.product" - tmpl_company_id = fields.Many2one( - related="product_tmpl_id.company_id", - string="Company of the related Template", - store=True, - ) - - def _auto_init(self): - for i, constraint in enumerate(self._sql_constraints): - if constraint[0] == "barcode_uniq": - self._sql_constraints[i] = ( - "barcode_uniq", - "unique(barcode, tmpl_company_id)", - _("A barcode can only be assigned to one product per company !"), - ) - return super(ProductProduct, self)._auto_init() + _sql_constraints = [ + # Replace constraint with same name + ( + "barcode_uniq", + "unique(barcode, company_id)", + _("A barcode can only be assigned to one product per company !"), + ) + ] diff --git a/product_barcode_constraint_per_company/readme/CONTRIBUTORS.rst b/product_barcode_constraint_per_company/readme/CONTRIBUTORS.rst index 5d184316bf32..36a2d836e861 100644 --- a/product_barcode_constraint_per_company/readme/CONTRIBUTORS.rst +++ b/product_barcode_constraint_per_company/readme/CONTRIBUTORS.rst @@ -1,2 +1,4 @@ * Sylvain LE GAL * Sulivan Lominchar +* Cetmix <@cetmix.com> +* Dessan Hemrayev diff --git a/product_barcode_constraint_per_company/tests/test_module.py b/product_barcode_constraint_per_company/tests/test_module.py index 78dc31b7be46..8c4c260d0a19 100644 --- a/product_barcode_constraint_per_company/tests/test_module.py +++ b/product_barcode_constraint_per_company/tests/test_module.py @@ -24,10 +24,6 @@ def test_create_same_company(self): product2 = self._create_product("Product 2", self.company_1) product2.flush() - def test_create_different_company(self): - self._create_product("Product 1", self.company_1) - self._create_product("Product 2", self.company_2) - def _create_product(self, name, company): vals = { "name": name,