From 68cf175e078df890e5d2eeef1dad284922eb2046 Mon Sep 17 00:00:00 2001 From: "Anh Thao Pham (pta)" Date: Fri, 2 Oct 2020 10:12:45 +0000 Subject: [PATCH] [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 Signed-off-by: Anh Thao PHAM --- addons/sale/models/sale.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 73708e13e51..8fb42672d1e 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -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