Skip to content

Commit 2838814

Browse files
authored
Merge pull request #37 from maasanto/fix-buyer-tax-id-matching
fix: match buyer company by tax ID instead of name
2 parents 4026a6f + b4ff792 commit 2838814

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

edocument/edocument/profiles/peppol/parser.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,18 @@ def parse_peppol_buyer(root, namespaces):
261261
buyer_party, ".//cac:PartyLegalEntity/cbc:RegistrationName", namespaces
262262
) or get_xml_text(buyer_party, ".//cac:PartyName/cbc:Name", namespaces)
263263

264-
# Try to find company
264+
# Buyer tax ID
265+
buyer_tax_id = get_xml_text(buyer_party, ".//cac:PartyTaxScheme/cbc:CompanyID", namespaces)
266+
267+
# Try to find company by tax ID first (more reliable than name)
265268
company = None
266-
if buyer_name and frappe.db.exists("Company", buyer_name):
269+
if buyer_tax_id:
270+
company = frappe.db.get_value("Company", {"tax_id": buyer_tax_id}, "name")
271+
272+
if not company and buyer_name and frappe.db.exists("Company", buyer_name):
267273
company = buyer_name
268274

269-
return {"company": company, "name": buyer_name}
275+
return {"company": company, "name": buyer_name, "tax_id": buyer_tax_id}
270276

271277

272278
def parse_peppol_line_items(

0 commit comments

Comments
 (0)