details:   https://code.tryton.org/tryton/commit/bf1e38173774
branch:    default
user:      Cédric Krier <[email protected]>
date:      Mon Jan 19 11:48:55 2026 +0100
description:
        Use the company IDs from UBL as identifier

        Closes #14515
diffstat:

 modules/edocument_ubl/edocument.py |  42 +++++++++++++++++++++----------------
 1 files changed, 24 insertions(+), 18 deletions(-)

diffs (75 lines):

diff -r f0e4a973d246 -r bf1e38173774 modules/edocument_ubl/edocument.py
--- a/modules/edocument_ubl/edocument.py        Mon Jan 19 11:34:14 2026 +0100
+++ b/modules/edocument_ubl/edocument.py        Mon Jan 19 11:48:55 2026 +0100
@@ -630,7 +630,11 @@
         pool = Pool()
         Party = pool.get('party.party')
 
-        for identifier in party_el.iterfind('./{*}PartyIdentification/{*}ID'):
+        for identifier in chain(
+                party_el.iterfind('./{*}PartyIdentification/{*}ID'),
+                party_el.iterfind('./{*}PartyLegalEntity/{*}CompanyID'),
+                party_el.iterfind('./{*}PartyTaxScheme/{*}CompanyID'),
+                ):
             if identifier.text:
                 parties = Party.search([
                         ('identifiers.code', '=', identifier.text),
@@ -648,10 +652,18 @@
             party_el.findtext('./{*}PartyLegalEntity/{*}RegistrationName')
             or party_el.findtext('./{*}PartyName/{*}Name'))
         identifiers = []
-        for identifier in party_el.iterfind('./{*}PartyIdentification/{*}ID'):
+        identifiers_done = set()
+        for identifier in chain(
+                party_el.iterfind('./{*}PartyIdentification/{*}ID'),
+                party_el.iterfind('./{*}PartyTaxScheme/{*}CompanyID'),
+                party_el.iterfind('./{*}PartyLegalEntity/{*}CompanyID'),
+                ):
             if identifier.text:
-                identifiers.append(cls._create_2_party_identifier(
-                        identifier))
+                identifier_key = (identifier.text, identifier.get('schemeID'))
+                if identifier_key not in identifiers_done:
+                    identifiers.append(cls._create_2_party_identifier(
+                            identifier))
+                identifiers_done.add(identifier_key)
         party.identifiers = identifiers
         if (address := party_el.find('./{*}PostalAddress')
                 ) is not None:
@@ -772,8 +784,12 @@
                         pass
                     else:
                         return customer_code.company
-        for identifier in customer_party.iterfind(
-                './{*}Party/{*}PartyIdentification/{*}ID'):
+        party_el = customer_party.find('./{*}Party')
+        for identifier in chain(
+                party_el.iterfind('./{*}PartyIdentification/{*}ID'),
+                party_el.iterfind('./{*}PartyTaxScheme/{*}CompanyID'),
+                party_el.iterfind('./{*}PartyLegalEntity/{*}CompanyID'),
+                ):
             if identifier.text:
                 companies = Company.search([
                         ('party.identifiers.code', '=', identifier.text),
@@ -782,19 +798,9 @@
                     company, = companies
                     return company
 
-        for company_id in customer_party.iterfind(
-                './{*}Party/{*}PartyTaxScheme/{*}CompanyID'):
-            companies = Company.search([
-                    ('party.identifiers.code', '=', company_id.text),
-                    ])
-            if len(companies) == 1:
-                company, = companies
-                return company
-
         for name in chain(
-                customer_party.iterfind(
-                    './{*}Party/{*}PartyTaxScheme/{*}RegistrationName'),
-                customer_party.iterfind('./{*}Party/{*}PartyName/{*}Name'),
+                party_el.iterfind('./{*}PartyTaxScheme/{*}RegistrationName'),
+                party_el.iterfind('./{*}PartyName/{*}Name'),
                 ):
             if name is None:
                 continue

Reply via email to