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: