diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index b8104a841d3..b95b4bf5109 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2633,11 +2633,7 @@ class AccountMoveLine(models.Model): if self.company_id and tax_ids: tax_ids = tax_ids.filtered(lambda tax: tax.company_id == self.company_id) - fiscal_position = self.move_id.fiscal_position_id - if tax_ids and fiscal_position: - return fiscal_position.map_tax(tax_ids, partner=self.partner_id) - else: - return tax_ids + return self.move_id.fiscal_position_id.map_tax(tax_ids, partner=self.partner_id) def _get_computed_uom(self): self.ensure_one() diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 95755d87045..40a200950c2 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -44,28 +44,21 @@ class AccountFiscalPosition(models.Model): if self.zip_from and self.zip_to and position.zip_from > position.zip_to: raise ValidationError(_('Invalid "Zip Range", please configure it properly.')) - @api.model # noqa def map_tax(self, taxes, product=None, partner=None): - result = self.env['account.tax'].browse() + if not self: + return taxes + result = self.env['account.tax'] for tax in taxes: - tax_count = 0 - for t in self.tax_ids: - if t.tax_src_id == tax: - tax_count += 1 - if t.tax_dest_id: - result |= t.tax_dest_id - if not tax_count: - result |= tax + taxes_correspondance = self.tax_ids.filtered(lambda t: t.tax_src_id == tax) + result |= taxes_correspondance.tax_dest_id if taxes_correspondance else tax return result - @api.model def map_account(self, account): for pos in self.account_ids: if pos.account_src_id == account: return pos.account_dest_id return account - @api.model def map_accounts(self, accounts): """ Receive a dictionary having accounts in values and try to replace those accounts accordingly to the fiscal position. """ diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 013bc199c42..472c9fb802b 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -25,8 +25,7 @@ class PosOrder(models.Model): @api.model def _amount_line_tax(self, line, fiscal_position_id): taxes = line.tax_ids.filtered(lambda t: t.company_id.id == line.order_id.company_id.id) - if fiscal_position_id: - taxes = fiscal_position_id.map_tax(taxes, line.product_id, line.order_id.partner_id) + taxes = fiscal_position_id.map_tax(taxes, line.product_id, line.order_id.partner_id) price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) taxes = taxes.compute_all(price, line.order_id.pricelist_id.currency_id, line.qty, product=line.product_id, partner=line.order_id.partner_id or False)['taxes'] return sum(tax.get('amount', 0.0) for tax in taxes) @@ -652,7 +651,7 @@ class PosOrderLine(models.Model): def _compute_amount_line_all(self): self.ensure_one() fpos = self.order_id.fiscal_position_id - tax_ids_after_fiscal_position = fpos.map_tax(self.tax_ids, self.product_id, self.order_id.partner_id) if fpos else self.tax_ids + tax_ids_after_fiscal_position = fpos.map_tax(self.tax_ids, self.product_id, self.order_id.partner_id) price = self.price_unit * (1 - (self.discount or 0.0) / 100.0) taxes = tax_ids_after_fiscal_position.compute_all(price, self.order_id.pricelist_id.currency_id, self.qty, product=self.product_id, partner=self.order_id.partner_id) return { @@ -671,8 +670,7 @@ class PosOrderLine(models.Model): self.product_id, self.qty or 1.0, self.order_id.partner_id) self._onchange_qty() self.tax_ids = self.product_id.taxes_id.filtered(lambda r: not self.company_id or r.company_id == self.company_id) - fpos = self.order_id.fiscal_position_id - tax_ids_after_fiscal_position = fpos.map_tax(self.tax_ids, self.product_id, self.order_id.partner_id) if fpos else self.tax_ids + tax_ids_after_fiscal_position = self.order_id.fiscal_position_id.map_tax(self.tax_ids, self.product_id, self.order_id.partner_id) 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) @api.onchange('qty', 'discount', 'price_unit', 'tax_ids') diff --git a/addons/point_of_sale/tests/common.py b/addons/point_of_sale/tests/common.py index cef2b387cdf..f1bb6ba1101 100644 --- a/addons/point_of_sale/tests/common.py +++ b/addons/point_of_sale/tests/common.py @@ -410,7 +410,7 @@ class TestPoSCommon(StockAccountTestCommon): def create_order_line(product, quantity): price_unit = self.pricelist.get_product_price(product, quantity, False) - tax_ids = fiscal_position.map_tax(product.taxes_id) if fiscal_position else product.taxes_id + tax_ids = fiscal_position.map_tax(product.taxes_id) tax_values = ( tax_ids.compute_all(price_unit, self.currency, quantity) if tax_ids diff --git a/addons/purchase_requisition/models/purchase.py b/addons/purchase_requisition/models/purchase.py index 51fbe41010f..e29b4d8c490 100644 --- a/addons/purchase_requisition/models/purchase.py +++ b/addons/purchase_requisition/models/purchase.py @@ -56,10 +56,7 @@ class PurchaseOrder(models.Model): name += '\n' + product_lang.description_purchase # Compute taxes - if fpos: - taxes_ids = fpos.map_tax(line.product_id.supplier_taxes_id.filtered(lambda tax: tax.company_id == requisition.company_id)).ids - else: - taxes_ids = line.product_id.supplier_taxes_id.filtered(lambda tax: tax.company_id == requisition.company_id).ids + taxes_ids = fpos.map_tax(line.product_id.supplier_taxes_id.filtered(lambda tax: tax.company_id == requisition.company_id)).ids # Compute quantity and price_unit if line.product_uom_id != line.product_id.uom_po_id: diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index 1bd553e9c52..53e402cda26 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -212,7 +212,7 @@ class StockRule(models.Model): taxes = product_id.supplier_taxes_id fpos = po.fiscal_position_id - taxes_id = fpos.map_tax(taxes, product_id, seller.name) if fpos else taxes + taxes_id = fpos.map_tax(taxes, product_id, seller.name) if taxes_id: taxes_id = taxes_id.filtered(lambda x: x.company_id.id == company_id.id) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index b528a82c43f..5a75f128195 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -1087,7 +1087,7 @@ class SaleOrderLine(models.Model): fpos = line.order_id.fiscal_position_id or line.order_id.partner_id.property_account_position_id # 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, line.product_id, line.order_id.partner_shipping_id) if fpos else taxes + line.tax_id = fpos.map_tax(taxes, line.product_id, line.order_id.partner_shipping_id) @api.model def _get_purchase_price(self, pricelist, product, product_uom, date): diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py index b612c74c835..d009fe3c4c5 100644 --- a/addons/sale/wizard/sale_make_invoice_advance.py +++ b/addons/sale/wizard/sale_make_invoice_advance.py @@ -137,10 +137,7 @@ class SaleAdvancePaymentInv(models.TransientModel): if self.product_id.type != 'service': raise UserError(_("The product used to invoice a down payment should be of type 'Service'. Please use another product or update this product.")) taxes = self.product_id.taxes_id.filtered(lambda r: not order.company_id or r.company_id == order.company_id) - if order.fiscal_position_id and taxes: - tax_ids = order.fiscal_position_id.map_tax(taxes, self.product_id, order.partner_shipping_id).ids - else: - tax_ids = taxes.ids + tax_ids = order.fiscal_position_id.map_tax(taxes, self.product_id, order.partner_shipping_id).ids context = {'lang': order.partner_id.lang} analytic_tag_ids = [] for line in order.order_line: diff --git a/addons/sale_coupon/models/sale_order.py b/addons/sale_coupon/models/sale_order.py index b8c2b9a8967..9447119da95 100644 --- a/addons/sale_coupon/models/sale_order.py +++ b/addons/sale_coupon/models/sale_order.py @@ -89,9 +89,7 @@ class SaleOrder(models.Model): reward_qty = min(int(int(max_product_qty / program.rule_min_quantity) * program.reward_product_quantity), reward_product_qty) # Take the default taxes on the reward product, mapped with the fiscal position - taxes = program.reward_product_id.taxes_id - if self.fiscal_position_id: - taxes = self.fiscal_position_id.map_tax(taxes) + taxes = self.fiscal_position_id.map_tax(program.reward_product_id.taxes_id) return { 'product_id': program.discount_line_product_id.id, 'price_unit': - price_unit, @@ -142,9 +140,7 @@ class SaleOrder(models.Model): if line: discount_line_amount = line.price_reduce * (program.discount_percentage / 100) if discount_line_amount: - taxes = line.tax_id - if self.fiscal_position_id: - taxes = self.fiscal_position_id.map_tax(taxes) + taxes = self.fiscal_position_id.map_tax(line.tax_id) reward_dict[line.tax_id] = { 'name': _("Discount: ") + program.name, @@ -169,9 +165,7 @@ class SaleOrder(models.Model): if line.tax_id in reward_dict: reward_dict[line.tax_id]['price_unit'] -= discount_line_amount else: - taxes = line.tax_id - if self.fiscal_position_id: - taxes = self.fiscal_position_id.map_tax(taxes) + taxes = self.fiscal_position_id.map_tax(line.tax_id) tax_name = "" if len(taxes) == 1: @@ -427,7 +421,7 @@ class SaleOrderLine(models.Model): fpos = line.order_id.fiscal_position_id or line.order_id.partner_id.property_account_position_id # If company_id is set, always filter taxes by the company taxes = line.tax_id.filtered(lambda r: not line.company_id or r.company_id == line.company_id) - line.tax_id = fpos.map_tax(taxes, line.product_id, line.order_id.partner_shipping_id) if fpos else taxes + line.tax_id = fpos.map_tax(taxes, line.product_id, line.order_id.partner_shipping_id) # Invalidation of `sale.coupon.program.order_count` # `test_program_rules_validity_dates_and_uses`, diff --git a/addons/sale_coupon_delivery/models/sale_order.py b/addons/sale_coupon_delivery/models/sale_order.py index dab962d9e78..44162a27af1 100644 --- a/addons/sale_coupon_delivery/models/sale_order.py +++ b/addons/sale_coupon_delivery/models/sale_order.py @@ -26,9 +26,7 @@ class SaleOrder(models.Model): def _get_reward_values_free_shipping(self, program): delivery_line = self.order_line.filtered(lambda x: x.is_delivery) - taxes = delivery_line.product_id.taxes_id - if self.fiscal_position_id: - taxes = self.fiscal_position_id.map_tax(taxes) + taxes = self.fiscal_position_id.map_tax(delivery_line.product_id.taxes_id) return { 'name': _("Discount: ") + program.name, 'product_id': program.discount_line_product_id.id, diff --git a/addons/sale_purchase/models/sale_order.py b/addons/sale_purchase/models/sale_order.py index fe54c2670c2..1219d3660c7 100644 --- a/addons/sale_purchase/models/sale_order.py +++ b/addons/sale_purchase/models/sale_order.py @@ -214,7 +214,7 @@ 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 fpos else self.product_id.supplier_taxes_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)