Skip to content
Snippets Groups Projects
Commit 106ae9ea authored by Adrien Minet's avatar Adrien Minet
Browse files

[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/odoo#87126

X-original-commit: fc853c21
Signed-off-by: default avatarAdrien Minet <admi@odoo.com>
Signed-off-by: default avatarWilliam André (wan) <wan@odoo.com>
parent eca5ea22
Branches
Tags
No related merge requests found
......@@ -310,6 +310,24 @@ class AccountEdiFormat(models.Model):
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)
# For Gross price, we need to check if a discount must be taken into account
discount_elements = element.xpath('.//ram:AppliedTradeAllowanceCharge',
namespaces=tree.nsmap)
if discount_elements:
discount_percent_elements = element.xpath(
'.//ram:AppliedTradeAllowanceCharge/ram:CalculationPercent', namespaces=tree.nsmap)
if discount_percent_elements:
invoice_line_form.discount = float(discount_percent_elements[0].text)
else:
# if discount not available, it will be computed from the gross and net prices.
net_price_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:ChargeAmount',
namespaces=tree.nsmap)
if net_price_elements:
quantity_elements = element.xpath(
'.//ram:NetPriceProductTradePrice/ram:BasisQuantity', namespaces=tree.nsmap)
net_unit_price = float(net_price_elements[0].text) / float(quantity_elements[0].text) \
if quantity_elements else float(net_price_elements[0].text)
invoice_line_form.discount = (invoice_line_form.price_unit - net_unit_price) / invoice_line_form.price_unit * 100.0
else:
line_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap)
if line_elements:
......@@ -318,10 +336,6 @@ class AccountEdiFormat(models.Model):
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:
invoice_line_form.discount = float(line_elements[0].text)
# Taxes
tax_element = element.xpath('.//ram:SpecifiedLineTradeSettlement/ram:ApplicableTradeTax/ram:RateApplicablePercent', namespaces=tree.nsmap)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment