[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#87509 X-original-commit: 43fb1c47b4867ac9b1fe7c3dd30e8bed7bd93f13 Signed-off-by: Adrien Minet <admi@odoo.com> Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
committed by
william-andre
parent
04861eaf9e
commit
1775b2e595
@@ -232,6 +232,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.
|
||||
else:
|
||||
line_elements = element.xpath('.//ram:NetPriceProductTradePrice/ram:ChargeAmount', namespaces=tree.nsmap)
|
||||
if line_elements:
|
||||
@@ -240,10 +258,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)
|
||||
|
||||
Reference in New Issue
Block a user