From b4ff79240bd1fc58eb7095a42e95760f41be65f2 Mon Sep 17 00:00:00 2001 From: Antoine Maas Date: Wed, 11 Feb 2026 11:05:27 +0100 Subject: [PATCH] fix: match buyer company by tax ID instead of name --- edocument/edocument/profiles/peppol/parser.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/edocument/edocument/profiles/peppol/parser.py b/edocument/edocument/profiles/peppol/parser.py index 4a01769..6580484 100644 --- a/edocument/edocument/profiles/peppol/parser.py +++ b/edocument/edocument/profiles/peppol/parser.py @@ -261,12 +261,18 @@ def parse_peppol_buyer(root, namespaces): buyer_party, ".//cac:PartyLegalEntity/cbc:RegistrationName", namespaces ) or get_xml_text(buyer_party, ".//cac:PartyName/cbc:Name", namespaces) - # Try to find company + # Buyer tax ID + buyer_tax_id = get_xml_text(buyer_party, ".//cac:PartyTaxScheme/cbc:CompanyID", namespaces) + + # Try to find company by tax ID first (more reliable than name) company = None - if buyer_name and frappe.db.exists("Company", buyer_name): + if buyer_tax_id: + company = frappe.db.get_value("Company", {"tax_id": buyer_tax_id}, "name") + + if not company and buyer_name and frappe.db.exists("Company", buyer_name): company = buyer_name - return {"company": company, "name": buyer_name} + return {"company": company, "name": buyer_name, "tax_id": buyer_tax_id} def parse_peppol_line_items(