From 4ffd2fdd81aad675194f9c21c097abdc99a0d3c0 Mon Sep 17 00:00:00 2001
From: Damien Bouvy <dbo@odoo.com>
Date: Thu, 26 May 2016 10:27:44 +0200
Subject: [PATCH] [FIX] sale: multi-company tax filtering

When the admin creates a SO, he has access to all taxes (since ir.rules
do not apply to him); therefore in some cases, the SO could be created
with SO lines that have taxes from other companies. This usually does
not make sense.

From this revision on, only taxes that are in the same company as the
SO are applied to the lines. If no company is set, then no filtering
is done.
---
 addons/sale/sale.py | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 4176d75229a3..ad6ef43a0364 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -545,17 +545,9 @@ class SaleOrderLine(models.Model):
     def _compute_tax_id(self):
         for line in self:
             fpos = line.order_id.fiscal_position_id or line.order_id.partner_id.property_account_position_id
-            if fpos:
-                # The superuser is used by website_sale in order to create a sale order. We need to make
-                # sure we only select the taxes related to the company of the partner. This should only
-                # apply if the partner is linked to a company.
-                if self.env.uid == SUPERUSER_ID and line.order_id.company_id:
-                    taxes = fpos.map_tax(line.product_id.taxes_id).filtered(lambda r: r.company_id == line.order_id.company_id)
-                else:
-                    taxes = fpos.map_tax(line.product_id.taxes_id)
-                line.tax_id = taxes
-            else:
-                line.tax_id = line.product_id.taxes_id if line.product_id.taxes_id else False
+            # If company_id is set, always filter taxes by the company
+            taxes = line.product_id.taxes_id.filtered(lambda r: not line.company_id or r.company_id == line.company_id)
+            line.tax_id = fpos.map_tax(taxes) if fpos else taxes
 
     @api.multi
     def _prepare_order_line_procurement(self, group_id=False):
-- 
GitLab