From 9bfeecdb0205c948f9a7be2216cc9e1e9de788b4 Mon Sep 17 00:00:00 2001 From: Bastian Guenther Date: Tue, 10 Dec 2024 16:24:01 +0100 Subject: [PATCH] [IMP] account_invoice_import_facturx: * Improved matching of partner * Improved matching of products * Added matching of operating unit * Improved account move line name --- .../__manifest__.py | 2 +- .../wizard/account_invoice_import.py | 97 ++++++++++++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/account_invoice_import_facturx/__manifest__.py b/account_invoice_import_facturx/__manifest__.py index 005e71df21..80b43d6a07 100644 --- a/account_invoice_import_facturx/__manifest__.py +++ b/account_invoice_import_facturx/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Account Invoice Import Factur-X", - "version": "13.0.1.0.0", + "version": "13.0.1.1.0", "category": "Invoicing Management", "license": "AGPL-3", "summary": "Import Factur-X/ZUGFeRD supplier invoices/refunds", diff --git a/account_invoice_import_facturx/wizard/account_invoice_import.py b/account_invoice_import_facturx/wizard/account_invoice_import.py index 2fa6dd2bb9..a5c5aaf448 100644 --- a/account_invoice_import_facturx/wizard/account_invoice_import.py +++ b/account_invoice_import_facturx/wizard/account_invoice_import.py @@ -44,6 +44,24 @@ def prepare_facturx_xpath_dict(self): "/ram:SpecifiedTaxRegistration" "/ram:ID[@schemeID='VA']", # ZUGFeRD ], + "tax_number": [ + "//ram:ApplicableHeaderTradeAgreement" + "/ram:SellerTradeParty" + "/ram:SpecifiedTaxRegistration" + "/ram:ID[@schemeID='FC']", # Factur-X + "//ram:ApplicableSupplyChainTradeAgreement" + "/ram:SellerTradeParty" + "/ram:SpecifiedTaxRegistration" + "/ram:ID[@schemeID='FC']", # ZUGFeRD + ], + "gln": [ + "//ram:ApplicableHeaderTradeAgreement" + "/ram:SellerTradeParty" + "/ram:GlobalID[@schemeID='0088']", # Factur-X + "//ram:ApplicableSupplyChainTradeAgreement" + "/ram:SellerTradeParty" + "/ram:GlobalID[@schemeID='0088']", # ZUGFeRD + ], "name": [ "//ram:ApplicableHeaderTradeAgreement" "/ram:SellerTradeParty" @@ -64,6 +82,18 @@ def prepare_facturx_xpath_dict(self): "/ram:EmailURIUniversalCommunication" "/ram:URIID", # ZUGFeRD ], + "phone": [ + "//ram:ApplicableHeaderTradeAgreement" + "/ram:SellerTradeParty" + "/ram:DefinedTradeContact" + "/ram:TelephoneUniversalCommunication" + "/ram:CompleteNumber", # Factur-X + "//ram:ApplicableSupplyChainTradeAgreement" + "/ram:SellerTradeParty" + "/ram:DefinedTradeContact" + "/ram:TelephoneUniversalCommunication" + "/ram:CompleteNumber", # ZUGFeRD + ], "country_code": [ "//ram:ApplicableHeaderTradeAgreement" "/ram:SellerTradeParty" @@ -112,6 +142,56 @@ def prepare_facturx_xpath_dict(self): "/ram:SpecifiedTaxRegistration" "/ram:ID[@schemeID='VA']", # ZUGFeRD ], + "tax_number": [ + "//ram:ApplicableHeaderTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:SpecifiedTaxRegistration" + "/ram:ID[@schemeID='FC']", # Factur-X + "//ram:ApplicableSupplyChainTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:SpecifiedTaxRegistration" + "/ram:ID[@schemeID='FC']", # ZUGFeRD + ], + "gln": [ + "//ram:ApplicableHeaderTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:GlobalID[@schemeID='0088']", # Factur-X + "//ram:ApplicableSupplyChainTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:GlobalID[@schemeID='0088']", # ZUGFeRD + ], + "name": [ + "//ram:ApplicableHeaderTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:Name", # Factur-X + "//ram:ApplicableSupplyChainTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:Name", # ZUGFeRD + ], + "email": [ + "//ram:ApplicableHeaderTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:DefinedTradeContact" + "/ram:EmailURIUniversalCommunication" + "/ram:URIID", # Factur-X + "//ram:ApplicableSupplyChainTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:DefinedTradeContact" + "/ram:EmailURIUniversalCommunication" + "/ram:URIID", # ZUGFeRD + ], + "phone": [ + "//ram:ApplicableHeaderTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:DefinedTradeContact" + "/ram:TelephoneUniversalCommunication" + "/ram:CompleteNumber", # Factur-X + "//ram:ApplicableSupplyChainTradeAgreement" + "/ram:BuyerTradeParty" + "/ram:DefinedTradeContact" + "/ram:TelephoneUniversalCommunication" + "/ram:CompleteNumber", # ZUGFeRD + ], }, "invoice_number": [ "//rsm:ExchangedDocument/ram:ID", # Factur-X @@ -257,6 +337,7 @@ def parse_facturx_invoice_line( "code": ["ram:SpecifiedTradeProduct/ram:SellerAssignedID"], }, "name": ["ram:SpecifiedTradeProduct/ram:Name"], + "description": ["ram:SpecifiedTradeProduct/ram:Description"], "date_start": [ "ram:SpecifiedLineTradeSettlement" "/ram:BillingSpecifiedPeriod" @@ -269,6 +350,18 @@ def parse_facturx_invoice_line( ], } vals = self.xpath_to_dict_helper(iline, xpath_dict, namespaces) + name_parts = [] + if vals.get("name"): + name_parts.append(vals.get("name")) + if vals.get("description"): + name_parts.append(vals.get("description")) + if vals.get("product"): + product = vals.get("product") + if product.get("code"): + name_parts.append(product.get("code")) + if product.get("barcode"): + name_parts.append(product.get("barcode")) + vals["name"] = "\n".join(name_parts) price_unit_xpath = iline.xpath( "ram:SpecifiedSupplyChainTradeAgreement" "/ram:NetPriceProductTradePrice" @@ -650,8 +743,10 @@ def parse_facturx_invoice(self, xml_root): # noqa: C901 ) # Hack for the sample ZUGFeRD invoices that use an invalid VAT number ! if res["partner"].get("vat") == "DE123456789": - res["partner"].pop("vat") + res["partner"]["vat"] = "DE123456788" if not res["partner"].get("email"): res["partner"]["name"] = "Lieferant GmbH" + if res["company"].get("vat") == "DE123456789": + res["company"]["vat"] = "DE123456788" logger.info("Result of Factur-X XML parsing: %s", res) return res