From 5d088e6a9040cbf6e348383923fadb349a07dc99 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 27 Aug 2019 13:21:16 +0000 Subject: [PATCH] [FIX] account_tax_python: product is a template - Create a new tax, using the 'Python Code' tax computation - In 'Applicable Code' field, use a field only available on the `product.product` model (e.g. `product.code`) - Attach this new tax to a product that is available in the eCommerce - Access the eCommerce, search for the product if not displayed. The template `website_sale.products_item` crashes at rendering because `code` is not available on a `product.template`. `product` is supposed to be a `product.product` recordset. However, the method `_get_combination_info` of `sale` is made in such a way that we can fetch the information of a template, not a product. Utlimately, methods `compute_all` and `_compute_amount` are called with the wrong object. We fall back on the first variant in this case. opw-2056722 closes odoo/odoo#36134 Signed-off-by: Nicolas Martinelli (nim) --- addons/account_tax_python/models/account_tax.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/account_tax_python/models/account_tax.py b/addons/account_tax_python/models/account_tax.py index 632b7375f40..87332f4fd86 100644 --- a/addons/account_tax_python/models/account_tax.py +++ b/addons/account_tax_python/models/account_tax.py @@ -28,6 +28,8 @@ class AccountTaxPython(models.Model): def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None): self.ensure_one() + if product and product._name == 'product.template': + product = product.product_variant_id if self.amount_type == 'code': company = self.env.user.company_id localdict = {'base_amount': base_amount, 'price_unit':price_unit, 'quantity': quantity, 'product':product, 'partner':partner, 'company': company} @@ -39,6 +41,8 @@ class AccountTaxPython(models.Model): def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None): taxes = self.filtered(lambda r: r.amount_type != 'code') company = self.env.user.company_id + if product and product._name == 'product.template': + product = product.product_variant_id for tax in self.filtered(lambda r: r.amount_type == 'code'): localdict = self._context.get('tax_computation_context', {}) localdict.update({'price_unit': price_unit, 'quantity': quantity, 'product': product, 'partner': partner, 'company': company})