From 5ecd42f048cc72774d787592cf533e740d350339 Mon Sep 17 00:00:00 2001 From: Jacques-Etienne Baudoux Date: Thu, 25 May 2023 12:23:32 +0200 Subject: [PATCH] [FIX] base_ubl: schemeID for GTIN is 0160 in peppol --- base_ubl/models/ubl.py | 5 +-- base_ubl/tests/__init__.py | 1 + base_ubl/tests/test_ubl_parse.py | 56 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 base_ubl/tests/test_ubl_parse.py diff --git a/base_ubl/models/ubl.py b/base_ubl/models/ubl.py index e7f3f2b0d8..354570645a 100644 --- a/base_ubl/models/ubl.py +++ b/base_ubl/models/ubl.py @@ -421,7 +421,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 @@ -784,8 +784,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")