From 291a94192c77e75e1f338a92ccc71898d7484433 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 11 Jan 2017 11:04:32 +0100 Subject: [PATCH] [FIX] sale, purchase: tax computation Set the company rounding policy to "Round Globally". Create the following SO (or PO), with a 7 % excluded tax: - Qty Price - 880.000 5.79 - 120.000 4.36 - 28.000 2.88 - 68.000 11.09 - 35.000 5.20 - 35.000 5.32 The total tax on the SO is 477.48, while it is 477.50 on the invoice generated from the SO. FORWARDPORT UP TO 10.0 Fixes #13687 opw-703519 --- addons/purchase/purchase.py | 7 ++++++- addons/sale/sale.py | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 360043ab1a4..2687b82c311 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -22,7 +22,12 @@ class PurchaseOrder(models.Model): amount_untaxed = amount_tax = 0.0 for line in order.order_line: amount_untaxed += line.price_subtotal - amount_tax += line.price_tax + # FORWARDPORT UP TO 10.0 + if order.company_id.tax_calculation_rounding_method == 'round_globally': + taxes = line.taxes_id.compute_all(line.price_unit, line.order_id.currency_id, line.product_qty, product=line.product_id, partner=line.order_id.partner_id) + amount_tax += sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])) + else: + amount_tax += line.price_tax order.update({ 'amount_untaxed': order.currency_id.round(amount_untaxed), 'amount_tax': order.currency_id.round(amount_tax), diff --git a/addons/sale/sale.py b/addons/sale/sale.py index a1ebe31b51e..7d9f52df6b7 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -29,7 +29,13 @@ class SaleOrder(models.Model): amount_untaxed = amount_tax = 0.0 for line in order.order_line: amount_untaxed += line.price_subtotal - amount_tax += line.price_tax + # FORWARDPORT UP TO 10.0 + if order.company_id.tax_calculation_rounding_method == 'round_globally': + price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) + taxes = line.tax_id.compute_all(price, line.order_id.currency_id, line.product_uom_qty, product=line.product_id, partner=line.order_id.partner_id) + amount_tax += sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])) + else: + amount_tax += line.price_tax order.update({ 'amount_untaxed': order.pricelist_id.currency_id.round(amount_untaxed), 'amount_tax': order.pricelist_id.currency_id.round(amount_tax),