Skip to content

Commit

Permalink
Merge PR #892 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by simahawk
  • Loading branch information
OCA-git-bot committed Oct 11, 2024
2 parents 9659a3a + 5ecd42f commit 0c54071
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base_ubl/models/ubl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
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) <[email protected]>
# 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")

0 comments on commit 0c54071

Please sign in to comment.