From ddf3d9a87808b1aa99a783626ba084d145d2c103 Mon Sep 17 00:00:00 2001 From: "Nicolas (vin)" Date: Wed, 16 Sep 2020 13:43:51 +0000 Subject: [PATCH] [FIX] account_facturx: fix upload of pdf using facturx There seems to be an issue with the import of factur-x pdf. The unit price is being divided by the quantity resulting in wrong values. This commit will correct that by dividing the unit price by the amount of products in one unit, instead of the amount of unit. Task id #2341111 X-original-commit: d3116ba7266270cb5ef8e018f65131003d0331ed --- .../models/account_edi_format.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/account_edi_facturx/models/account_edi_format.py b/addons/account_edi_facturx/models/account_edi_format.py index 196553ddc40..7da91c9db6f 100644 --- a/addons/account_edi_facturx/models/account_edi_format.py +++ b/addons/account_edi_facturx/models/account_edi_format.py @@ -256,12 +256,19 @@ class AccountEdiFormat(models.Model): # Price Unit. line_elements = element.xpath('.//ram:GrossPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap) if line_elements: - invoice_line_form.price_unit = float(line_elements[0].text) / invoice_line_form.quantity + quantity_elements = element.xpath('.//ram:GrossPriceProductTradePrice/ram:BasisQuantity', namespaces=tree.nsmap) + if quantity_elements: + invoice_line_form.price_unit = float(line_elements[0].text) / float(quantity_elements[0].text) + else: + invoice_line_form.price_unit = float(line_elements[0].text) else: line_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap) if line_elements: - invoice_line_form.price_unit = float(line_elements[0].text) / invoice_line_form.quantity - + quantity_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:BasisQuantity', namespaces=tree.nsmap) + if quantity_elements: + invoice_line_form.price_unit = float(line_elements[0].text) / float(quantity_elements[0].text) + else: + invoice_line_form.price_unit = float(line_elements[0].text) # Discount. line_elements = element.xpath('.//ram:AppliedTradeAllowanceCharge/ram:CalculationPercent', namespaces=tree.nsmap) if line_elements: