-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] product_barcode_constraint_per_company
Simplify logic
- Loading branch information
1 parent
4951551
commit 6cc4f18
Showing
4 changed files
with
16 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
product_barcode_constraint_per_company/models/product_product.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 !"), | ||
) | ||
] |
2 changes: 2 additions & 0 deletions
2
product_barcode_constraint_per_company/readme/CONTRIBUTORS.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters