[FIX] sale: fix untaxed_amount_to_invoice field computation

- Go to Invoicing > Configuration > Taxes
- Create a Tax and enable "Included in Price" in Advanced Options tab
- Go to Sales and create a Quotation:
  * Add an Order Line with the created Tax
- Save & Confirm
- Edit the Quotation to set a delivery quantity, then save
- Go to Sales > Reporting > Sales:
  * Display row by "Order #"
  * In Measures, add "Untaxed Amount to Invoice"
- Check the values for the create SO
The amount for "Untaxed Amount to Invoice" is the amount with taxes included.

It is due to the fact that untaxed_amount_to_invoice field of sale.order.line is computed
from price_reduce field.
As price_reduce is computed from price_unit, if there is a tax that is included in the price,
price_reduce will also contain the tax in its value.

opw-2347571

closes odoo/odoo#59334

X-original-commit: 8c54ed42eef16817f198f10697820eddcc7d0c74
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
Signed-off-by: Anh Thao PHAM <kitan191@users.noreply.github.com>
This commit is contained in:
Anh Thao Pham (pta)
2020-10-07 06:40:47 +00:00
parent 84f8651135
commit 68cf175e07
+5
View File
@@ -1505,6 +1505,11 @@ class SaleOrderLine(models.Model):
price_subtotal = line.price_reduce * line.qty_delivered
else:
price_subtotal = line.price_reduce * line.product_uom_qty
if len(line.tax_id.filtered(lambda tax: tax.price_include)) > 0:
# As included taxes are not excluded from the computed subtotal, `compute_all()` method
# has to be called to retrieve the subtotal without them.
# `price_reduce_taxexcl` cannot be used as it is computed from `price_subtotal` field. (see upper Note)
price_subtotal = line.tax_id.compute_all(price_subtotal)['total_excluded']
amount_to_invoice = price_subtotal - line.untaxed_amount_invoiced
line.untaxed_amount_to_invoice = amount_to_invoice