Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] base_ubl: schemeID for GTIN is 0160 #892

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions base_ubl/models/ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions base_ubl/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions base_ubl/tests/test_ubl_parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2024 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# 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"""<?xml version="1.0" encoding="UTF-8" ?>
<Root
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
>
<cac:Item>
<cbc:Description>Acme beeswax</cbc:Description>
<cbc:Name>beeswax</cbc:Name>
<cac:StandardItemIdentification>
<cbc:ID schemeID="GTIN">6578489</cbc:ID>
</cac:StandardItemIdentification>
<cac:SellersItemIdentification>
<cbc:ID>17589683</cbc:ID>
</cac:SellersItemIdentification>
</cac:Item>
</Root>
"""
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"""<?xml version="1.0" encoding="UTF-8" ?>
<Root
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
>
<cac:Item>
<cbc:Description>Acme beeswax</cbc:Description>
<cbc:Name>beeswax</cbc:Name>
<cac:StandardItemIdentification>
<cbc:ID schemeID="0160">6578489</cbc:ID>
</cac:StandardItemIdentification>
<cac:SellersItemIdentification>
<cbc:ID>17589683</cbc:ID>
</cac:SellersItemIdentification>
</cac:Item>
</Root>
"""
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")
Loading