Skip to content

Commit 11d1069

Browse files
committed
[FIX] stock_barcodes_gs1: process barcode like non gs1 if is ean valid.
1 parent 039736d commit 11d1069

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

stock_barcodes_gs1/wizard/stock_barcodes_read.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright 2019 Sergio Teruel <[email protected]>
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3-
from odoo import _, models
3+
from odoo import _, api, models
4+
from odoo.tools import check_barcode_encoding
5+
6+
BARCODE_ENCODING = ["ean8", "ean13", "gtin14", "upca", "sscc"]
47

58

69
class WizStockBarcodesRead(models.AbstractModel):
@@ -128,11 +131,23 @@ def _is_lot_ai_in_barcode(gs1_list):
128131
"""Helper method to know if the Lot/Serial is included in barcode"""
129132
return next(filter(lambda f: f["ai"] == "10", gs1_list), False)
130133

134+
@api.model
135+
def _ean_barcode_valid(self, barcode):
136+
"""Check if barcode is valid and not GS1"""
137+
for encoding in BARCODE_ENCODING:
138+
if check_barcode_encoding(barcode, encoding):
139+
return True
140+
return False
141+
131142
def process_barcode(self, barcode):
132143
nomenclature = self.env.company.nomenclature_id.filtered(
133144
"is_gs1_nomenclature"
134145
) or self.env.ref("barcodes_gs1_nomenclature.default_gs1_nomenclature")
135-
gs1_list = nomenclature.parse_barcode(barcode)
146+
gs1_list = None
147+
if nomenclature.gs1_separator_fnc1 in barcode or not self._ean_barcode_valid(
148+
barcode
149+
):
150+
gs1_list = nomenclature.parse_barcode(barcode)
136151
if gs1_list is None:
137152
return super().process_barcode(barcode)
138153
warning_msg_list = []

0 commit comments

Comments
 (0)