Skip to content

Commit

Permalink
[IMP] product_barcode_constraint_per_company
Browse files Browse the repository at this point in the history
Simplify logic
  • Loading branch information
dessanhemrayev committed Oct 29, 2023
1 parent 4951551 commit 6cc4f18
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
7 changes: 4 additions & 3 deletions product_barcode_constraint_per_company/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
26 changes: 10 additions & 16 deletions product_barcode_constraint_per_company/models/product_product.py
Original file line number Diff line number Diff line change
@@ -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 !"),
)
]
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>
* Sulivan Lominchar <slominchar@archeti.com>
* Cetmix <@cetmix.com>
* Dessan Hemrayev <dessanhemrayev@gmail.com>
4 changes: 0 additions & 4 deletions product_barcode_constraint_per_company/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6cc4f18

Please sign in to comment.