|
1 | 1 | # Copyright 2019 Sergio Teruel <[email protected]> |
2 | 2 | # 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"] |
4 | 7 |
|
5 | 8 |
|
6 | 9 | class WizStockBarcodesRead(models.AbstractModel): |
@@ -128,11 +131,23 @@ def _is_lot_ai_in_barcode(gs1_list): |
128 | 131 | """Helper method to know if the Lot/Serial is included in barcode""" |
129 | 132 | return next(filter(lambda f: f["ai"] == "10", gs1_list), False) |
130 | 133 |
|
| 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 | + |
131 | 142 | def process_barcode(self, barcode): |
132 | 143 | nomenclature = self.env.company.nomenclature_id.filtered( |
133 | 144 | "is_gs1_nomenclature" |
134 | 145 | ) 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) |
136 | 151 | if gs1_list is None: |
137 | 152 | return super().process_barcode(barcode) |
138 | 153 | warning_msg_list = [] |
|
0 commit comments