Skip to content

Commit

Permalink
[IMP] account_invoice_import_facturx:
Browse files Browse the repository at this point in the history
* Improved matching of partner
* Improved matching of products
* Added matching of operating unit
* Improved account move line name
  • Loading branch information
Bastian Guenther authored and Bastian Guenther committed Dec 10, 2024
1 parent 754e9be commit 9bfeecd
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
2 changes: 1 addition & 1 deletion account_invoice_import_facturx/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
97 changes: 96 additions & 1 deletion account_invoice_import_facturx/wizard/account_invoice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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

0 comments on commit 9bfeecd

Please sign in to comment.