From 2e3dac8da05d447b6373b53b70487fce1dc08946 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Wed, 2 Jun 2021 09:19:18 +0000 Subject: [PATCH] [IMP] *: do not filter the taxes twice for nothing Since _filter_included_tax_company filters the taxes of other companies, there is no need to give taxes from other companies if the filtering was already done. closes odoo/odoo#71591 Related: odoo/enterprise#18670 Signed-off-by: Victor Feyens (vfe) --- addons/point_of_sale/models/pos_order.py | 2 +- addons/purchase/models/purchase.py | 12 +++++------- addons/sale_purchase/models/sale_order.py | 6 +++--- addons/website_sale/models/product.py | 9 ++++++--- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 46fa45a4545..ce0609669cd 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -836,7 +836,7 @@ class PosOrderLine(models.Model): self.product_id, self.qty or 1.0, self.order_id.partner_id) self.tax_ids = self.product_id.taxes_id.filtered(lambda r: not self.company_id or r.company_id == self.company_id) tax_ids_after_fiscal_position = self.order_id.fiscal_position_id.map_tax(self.tax_ids) - self.price_unit = self.env['account.tax']._fix_tax_included_price_company(price, self.product_id.taxes_id, tax_ids_after_fiscal_position, self.company_id) + self.price_unit = self.env['account.tax']._fix_tax_included_price_company(price, self.tax_ids, tax_ids_after_fiscal_position, self.company_id) self._onchange_qty() @api.onchange('qty', 'discount', 'price_unit', 'tax_ids') diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index eab9fb65e1c..3e8de6c93e5 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -1285,13 +1285,11 @@ class PurchaseOrderLine(models.Model): date=po.date_order and po.date_order.date(), uom_id=product_id.uom_po_id) - taxes = product_id.supplier_taxes_id - fpos = po.fiscal_position_id - taxes_id = fpos.map_tax(taxes) - if taxes_id: - taxes_id = taxes_id.filtered(lambda x: x.company_id.id == company_id.id) + product_taxes = product_id.supplier_taxes_id.filtered(lambda x: x.company_id.id == company_id.id) + taxes = po.fiscal_position_id.map_tax(product_taxes) - price_unit = self.env['account.tax']._fix_tax_included_price_company(seller.price, product_id.supplier_taxes_id, taxes_id, company_id) if seller else 0.0 + price_unit = self.env['account.tax']._fix_tax_included_price_company( + seller.price, product_taxes, taxes, company_id) if seller else 0.0 if price_unit and seller and po.currency_id and seller.currency_id != po.currency_id: price_unit = seller.currency_id._convert( price_unit, po.currency_id, po.company_id, po.date_order or fields.Date.today()) @@ -1313,7 +1311,7 @@ class PurchaseOrderLine(models.Model): 'product_uom': product_id.uom_po_id.id, 'price_unit': price_unit, 'date_planned': date_planned, - 'taxes_id': [(6, 0, taxes_id.ids)], + 'taxes_id': [(6, 0, taxes.ids)], 'order_id': po.id, } diff --git a/addons/sale_purchase/models/sale_order.py b/addons/sale_purchase/models/sale_order.py index 751135ebe49..46a43535e88 100644 --- a/addons/sale_purchase/models/sale_order.py +++ b/addons/sale_purchase/models/sale_order.py @@ -229,14 +229,14 @@ class SaleOrderLine(models.Model): date=purchase_order.date_order and purchase_order.date_order.date(), # and purchase_order.date_order[:10], uom_id=self.product_id.uom_po_id ) - fpos = purchase_order.fiscal_position_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) + taxes = purchase_order.fiscal_position_id.map_tax(supplier_taxes) # compute unit price price_unit = 0.0 if supplierinfo: - price_unit = self.env['account.tax'].sudo()._fix_tax_included_price_company(supplierinfo.price, self.product_id.supplier_taxes_id, taxes, self.company_id) + price_unit = self.env['account.tax'].sudo()._fix_tax_included_price_company( + supplierinfo.price, supplier_taxes, taxes, self.company_id) if purchase_order.currency_id and supplierinfo.currency_id != purchase_order.currency_id: price_unit = supplierinfo.currency_id.compute(price_unit, purchase_order.currency_id) diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index d7a8543fe6d..747ed0cec02 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -300,14 +300,17 @@ class ProductTemplate(models.Model): tax_display = self.user_has_groups('account.group_show_line_subtotals_tax_excluded') and 'total_excluded' or 'total_included' fpos = self.env['account.fiscal.position'].get_fiscal_position(partner.id).sudo() - taxes = fpos.map_tax(product.sudo().taxes_id.filtered(lambda x: x.company_id == company_id)) + product_taxes = product.sudo().taxes_id.filtered(lambda x: x.company_id == company_id) + taxes = fpos.map_tax(product_taxes) # The list_price is always the price of one. quantity_1 = 1 - combination_info['price'] = self.env['account.tax']._fix_tax_included_price_company(combination_info['price'], product.sudo().taxes_id, taxes, company_id) + combination_info['price'] = self.env['account.tax']._fix_tax_included_price_company( + combination_info['price'], product_taxes, taxes, company_id) price = taxes.compute_all(combination_info['price'], pricelist.currency_id, quantity_1, product, partner)[tax_display] if pricelist.discount_policy == 'without_discount': - combination_info['list_price'] = self.env['account.tax']._fix_tax_included_price_company(combination_info['list_price'], product.sudo().taxes_id, taxes, company_id) + combination_info['list_price'] = self.env['account.tax']._fix_tax_included_price_company( + combination_info['list_price'], product_taxes, taxes, company_id) list_price = taxes.compute_all(combination_info['list_price'], pricelist.currency_id, quantity_1, product, partner)[tax_display] else: list_price = price