[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.
This commit is contained in:
Damien Bouvy
2016-05-26 11:22:03 +02:00
parent e07fa2601e
commit 4ffd2fdd81
+3 -11
View File
@@ -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):