diff --git a/base_ubl/models/ubl.py b/base_ubl/models/ubl.py index 8ef178ab5d..658d5a45e4 100644 --- a/base_ubl/models/ubl.py +++ b/base_ubl/models/ubl.py @@ -415,7 +415,7 @@ def _ubl_add_item( std_identification, ns["cbc"] + "ID", schemeAgencyID="6", - schemeID="GTIN", + schemeID="0160", # GTIN = 0160 ) std_identification_id.text = product.barcode # I'm not 100% sure, but it seems that ClassifiedTaxCategory @@ -771,8 +771,9 @@ def ubl_parse_incoterm(self, delivery_term_node, ns): return {} def ubl_parse_product(self, line_node, ns): + # GTIN schemeID is 0160 in peppol barcode_xpath = line_node.xpath( - "cac:Item/cac:StandardItemIdentification/cbc:ID[@schemeID='GTIN']", + "cac:Item/cac:StandardItemIdentification/cbc:ID[@schemeID=('0160' or 'GTIN')]", namespaces=ns, ) code_xpath = line_node.xpath( diff --git a/base_ubl/tests/__init__.py b/base_ubl/tests/__init__.py index 895163754b..39e1569862 100644 --- a/base_ubl/tests/__init__.py +++ b/base_ubl/tests/__init__.py @@ -1,3 +1,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import test_ubl_generate +from . import test_ubl_parse diff --git a/base_ubl/tests/test_ubl_parse.py b/base_ubl/tests/test_ubl_parse.py new file mode 100644 index 0000000000..b21d94a668 --- /dev/null +++ b/base_ubl/tests/test_ubl_parse.py @@ -0,0 +1,56 @@ +# Copyright 2024 Jacques-Etienne Baudoux (BCIM) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from lxml import etree + +from odoo.tests.common import TransactionCase + + +class TestBaseUblParse(TransactionCase): + def test_parse_product_schemeid_gtin(self): + xml_string = b""" + + + Acme beeswax + beeswax + + 6578489 + + + 17589683 + + + + """ + xml_root = etree.fromstring(xml_string) + ns = xml_root.nsmap + product = self.env["base.ubl"].ubl_parse_product(xml_root, ns) + self.assertEqual(product.get("barcode"), "6578489") + self.assertEqual(product.get("code"), "17589683") + + def test_parse_product_schemeid_0160(self): + xml_string = b""" + + + Acme beeswax + beeswax + + 6578489 + + + 17589683 + + + + """ + xml_root = etree.fromstring(xml_string) + ns = xml_root.nsmap + product = self.env["base.ubl"].ubl_parse_product(xml_root, ns) + self.assertEqual(product.get("barcode"), "6578489") + self.assertEqual(product.get("code"), "17589683")