[IMP] sale: Use a cache to compute fiscal positions
This commit is contained in:
@@ -403,7 +403,7 @@ class SaleOrder(models.Model):
|
||||
if not order.partner_id:
|
||||
order.fiscal_position_id = False
|
||||
continue
|
||||
key = (order.company_id, order.partner_id, order.partner_shipping_id)
|
||||
key = (order.company_id.id, order.partner_id.id, order.partner_shipping_id.id)
|
||||
if key not in cache:
|
||||
cache[key] = self.env['account.fiscal.position'].with_company(
|
||||
order.company_id
|
||||
|
||||
@@ -139,9 +139,12 @@ class SaleOrderLine(models.Model):
|
||||
|
||||
@api.depends('product_id')
|
||||
def _compute_tax_id(self):
|
||||
cached_fpos = {}
|
||||
for line in self:
|
||||
line = line.with_company(line.company_id)
|
||||
fpos = line.order_id.fiscal_position_id or line.order_id.fiscal_position_id._get_fiscal_position(line.order_partner_id)
|
||||
if line.order_id not in cached_fpos:
|
||||
cached_fpos[line.order_id] = line.order_id.fiscal_position_id or line.order_id.fiscal_position_id._get_fiscal_position(line.order_partner_id)
|
||||
fpos = cached_fpos[line.order_id]
|
||||
# If company_id is set, always filter taxes by the company
|
||||
taxes = line.product_id.taxes_id.filtered(lambda t: t.company_id == line.env.company)
|
||||
line.tax_id = fpos.map_tax(taxes)
|
||||
|
||||
Reference in New Issue
Block a user