diff --git a/addons/account_edi_ubl_cii/models/account_edi_common.py b/addons/account_edi_ubl_cii/models/account_edi_common.py index f4b2c3e35c0..f1fff941e72 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_common.py +++ b/addons/account_edi_ubl_cii/models/account_edi_common.py @@ -118,9 +118,9 @@ class AccountEdiCommon(models.AbstractModel): return UOM_TO_UNECE_CODE.get(xmlid[line.product_uom_id.id], 'C62') return 'C62' - def _find_value(self, xpath, tree): + def _find_value(self, xpath, tree, nsmap=False): # avoid 'TypeError: empty namespace prefix is not supported in XPath' - nsmap = {k: v for k, v in tree.nsmap.items() if k is not None} + nsmap = nsmap or {k: v for k, v in tree.nsmap.items() if k is not None} return find_xml_value(xpath, tree, nsmap) # ------------------------------------------------------------------------- diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py index 54dfa598f03..6b563c2299a 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py @@ -5,12 +5,21 @@ from lxml import etree from odoo import models, _ from odoo.tools import html2plaintext, cleanup_xml_node +UBL_NAMESPACES = { + 'cbc': "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2", + 'cac': "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2", +} + class AccountEdiXmlUBL20(models.AbstractModel): _name = "account.edi.xml.ubl_20" _inherit = 'account.edi.common' _description = "UBL 2.0" + def _find_value(self, xpath, tree, nsmap=False): + # EXTENDS account.edi.common + return super()._find_value(xpath, tree, UBL_NAMESPACES) + # ------------------------------------------------------------------------- # EXPORT # ------------------------------------------------------------------------- @@ -600,11 +609,11 @@ class AccountEdiXmlUBL20(models.AbstractModel): # ==== partner_id ==== role = "Customer" if invoice.journal_id.type == 'sale' else "Supplier" - vat = self._find_value(f'//cac:Accounting{role}Party/cac:Party//cbc:CompanyID[string-length(text()) > 5]', tree) - phone = self._find_value(f'//cac:Accounting{role}Party/cac:Party//cbc:Telephone', tree) - mail = self._find_value(f'//cac:Accounting{role}Party/cac:Party//cbc:ElectronicMail', tree) - name = self._find_value(f'//cac:Accounting{role}Party/cac:Party//cbc:Name', tree) - country_code = self._find_value(f'//cac:Accounting{role}Party/cac:Party//cac:Country//cbc:IdentificationCode', tree) + vat = self._find_value(f'.//cac:Accounting{role}Party/cac:Party//cbc:CompanyID[string-length(text()) > 5]', tree) + phone = self._find_value(f'.//cac:Accounting{role}Party/cac:Party//cbc:Telephone', tree) + mail = self._find_value(f'.//cac:Accounting{role}Party/cac:Party//cbc:ElectronicMail', tree) + name = self._find_value(f'.//cac:Accounting{role}Party/cac:Party//cbc:Name', tree) + country_code = self._find_value(f'.//cac:Accounting{role}Party/cac:Party//cac:Country//cbc:IdentificationCode', tree) self._import_retrieve_and_fill_partner(invoice, name=name, phone=phone, mail=mail, vat=vat, country_code=country_code) # ==== currency_id ====