Skip to content

Commit 43fb1c4

Browse files
admi2806william-andre
authored andcommitted
[FIX] account_factux: discount taken only for gross price
How to reproduce the bug: - Install the account app - Get a FacturX invoice with a discount on item - Upload the invoice - Check that the price of the discounted item takes the discount into account Bug: If you want to upload a FacturX invoice that contains a discount, Odoo will take the original price into account instead of the discounted one. opw-2705291 closes odoo#87129 X-original-commit: fc853c2 Signed-off-by: Adrien Minet <admi@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
1 parent 91787ae commit 43fb1c4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

addons/account_edi_facturx/models/account_edi_format.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,24 @@ def _find_value(xpath, element=tree):
260260
invoice_line_form.price_unit = float(line_elements[0].text) / float(quantity_elements[0].text)
261261
else:
262262
invoice_line_form.price_unit = float(line_elements[0].text)
263+
# For Gross price, we need to check if a discount must be taken into account
264+
discount_elements = element.xpath('.//ram:AppliedTradeAllowanceCharge',
265+
namespaces=tree.nsmap)
266+
if discount_elements:
267+
discount_percent_elements = element.xpath(
268+
'.//ram:AppliedTradeAllowanceCharge/ram:CalculationPercent', namespaces=tree.nsmap)
269+
if discount_percent_elements:
270+
invoice_line_form.discount = float(discount_percent_elements[0].text)
271+
else:
272+
# if discount not available, it will be computed from the gross and net prices.
273+
net_price_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:ChargeAmount',
274+
namespaces=tree.nsmap)
275+
if net_price_elements:
276+
quantity_elements = element.xpath(
277+
'.//ram:NetPriceProductTradePrice/ram:BasisQuantity', namespaces=tree.nsmap)
278+
net_unit_price = float(net_price_elements[0].text) / float(quantity_elements[0].text) \
279+
if quantity_elements else float(net_price_elements[0].text)
280+
invoice_line_form.discount = (invoice_line_form.price_unit - net_unit_price) / invoice_line_form.price_unit * 100.
263281
else:
264282
line_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap)
265283
if line_elements:
@@ -268,10 +286,6 @@ def _find_value(xpath, element=tree):
268286
invoice_line_form.price_unit = float(line_elements[0].text) / float(quantity_elements[0].text)
269287
else:
270288
invoice_line_form.price_unit = float(line_elements[0].text)
271-
# Discount.
272-
line_elements = element.xpath('.//ram:AppliedTradeAllowanceCharge/ram:CalculationPercent', namespaces=tree.nsmap)
273-
if line_elements:
274-
invoice_line_form.discount = float(line_elements[0].text)
275289

276290
# Taxes
277291
tax_element = element.xpath('.//ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:RateApplicablePercent', namespaces=tree.nsmap)

0 commit comments

Comments
 (0)