[FIX] pos,repair,sale(_*): multi-company taxes management

Since product can be shared between multiple companies, their taxes m2m
fields may hold taxes from multiple companies.  When working in sudoed
or multi-company environments, those taxes were incorrectly filtered and
taxes from other companies may erroneously impact records from other
companies.

This commit ensures that the product taxes are properly filtered to only
consider the ones from the current/record company.
This commit is contained in:
Victor Feyens
2021-06-17 12:14:36 +00:00
parent 2d43dc2afd
commit 9df95cb554
3 changed files with 6 additions and 8 deletions
+2 -2
View File
@@ -846,8 +846,8 @@ class PosOrderLine(models.Model):
raise UserError(_('You have to select a pricelist in the sale form.'))
price = self.price_unit * (1 - (self.discount or 0.0) / 100.0)
self.price_subtotal = self.price_subtotal_incl = price * self.qty
if (self.product_id.taxes_id):
taxes = self.product_id.taxes_id.compute_all(price, self.order_id.pricelist_id.currency_id, self.qty, product=self.product_id, partner=False)
if (self.tax_ids):
taxes = self.tax_ids.compute_all(price, self.order_id.pricelist_id.currency_id, self.qty, product=self.product_id, partner=False)
self.price_subtotal = taxes['total_excluded']
self.price_subtotal_incl = taxes['total_included']
+2 -3
View File
@@ -140,9 +140,8 @@ class SaleOrder(models.Model):
def _get_reward_values_discount(self, program):
if program.discount_type == 'fixed_amount':
taxes = program.discount_line_product_id.taxes_id
if self.fiscal_position_id:
taxes = self.fiscal_position_id.map_tax(taxes)
product_taxes = program.discount_line_product_id.taxes_id.filtered(lambda tax: tax.company_id == self.company_id)
taxes = self.fiscal_position_id.map_tax(product_taxes)
return [{
'name': _("Discount: %s", program.name),
'product_id': program.discount_line_product_id.id,
+2 -3
View File
@@ -230,9 +230,8 @@ class SaleOrderLine(models.Model):
uom_id=self.product_id.uom_po_id
)
fpos = purchase_order.fiscal_position_id
taxes = fpos.map_tax(self.product_id.supplier_taxes_id)
if taxes:
taxes = taxes.filtered(lambda t: t.company_id.id == self.company_id.id)
supplier_taxes = self.product_id.supplier_taxes_id.filtered(lambda t: t.company_id.id == self.company_id.id)
taxes = fpos.map_tax(supplier_taxes)
# compute unit price
price_unit = 0.0