From fecff7119f61ff04f40c71438f800a72ac88aff7 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 10 Nov 2021 13:27:55 +0100 Subject: [PATCH] [IMP] sale: Don't recompute taxes on tax configuration change This should be done manually --- addons/sale/models/sale_order_line.py | 6 ++++-- addons/sale/tests/test_sale_pricelist.py | 6 ++---- addons/sale_coupon/models/sale_order.py | 2 +- addons/sale_coupon/tests/test_program_numbers.py | 4 +++- addons/sale_management/models/sale_order.py | 2 +- .../test_website_sale_product_attribute_value_config.py | 5 +++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/addons/sale/models/sale_order_line.py b/addons/sale/models/sale_order_line.py index 7c1e64ed496..778061745da 100644 --- a/addons/sale/models/sale_order_line.py +++ b/addons/sale/models/sale_order_line.py @@ -134,7 +134,7 @@ class SaleOrderLine(models.Model): for line in self: line.price_reduce_taxexcl = line.price_subtotal / line.product_uom_qty if line.product_uom_qty else 0.0 - @api.depends('order_id.fiscal_position_id', 'tax_id.price_include') + @api.depends('product_id') def _compute_tax_id(self): for line in self: line = line.with_company(line.company_id) @@ -682,8 +682,8 @@ class SaleOrderLine(models.Model): 'order_id.partner_id') def _compute_price_unit(self): for line in self: - line.price_unit = 0.0 if not line.product_uom or not line.product_id: + line.price_unit = 0.0 continue if line.order_id.pricelist_id and line.order_id.partner_id: product = line.product_id.with_context( @@ -697,6 +697,8 @@ class SaleOrderLine(models.Model): ) line.price_unit = self.env['account.tax']._fix_tax_included_price_company( line._get_display_price(product), product.taxes_id, line.tax_id, line.company_id) + else: + line.price_unit = 0.0 def name_get(self): result = [] diff --git a/addons/sale/tests/test_sale_pricelist.py b/addons/sale/tests/test_sale_pricelist.py index 70592b12973..a1db9f509ac 100644 --- a/addons/sale/tests/test_sale_pricelist.py +++ b/addons/sale/tests/test_sale_pricelist.py @@ -120,8 +120,7 @@ class TestSaleOrder(TestSaleCommon): # Change the pricelist self.sale_order.write({'pricelist_id': self.pricelist_discount_incl.id}) # Trigger manually the computation for discount, unit price, subtotal, ... - self.sale_order.order_line._compute_price_unit() - self.sale_order.order_line._compute_discount() + self.sale_order.update_prices() # Check that pricelist of the SO has been applied on the sale order lines or not for line in self.sale_order.order_line: @@ -144,8 +143,7 @@ class TestSaleOrder(TestSaleCommon): # Change the pricelist self.sale_order.write({'pricelist_id': self.pricelist_discount_excl.id}) # Trigger manually the computation for discount, unit price, subtotal, ... - self.sale_order.order_line._compute_price_unit() - self.sale_order.order_line._compute_discount() + self.sale_order.update_prices() # Check pricelist of the SO apply or not on order lines where pricelist contains formula that add 15% on the cost price for line in self.sale_order.order_line: diff --git a/addons/sale_coupon/models/sale_order.py b/addons/sale_coupon/models/sale_order.py index 4d10d67889c..7b234ca1de6 100644 --- a/addons/sale_coupon/models/sale_order.py +++ b/addons/sale_coupon/models/sale_order.py @@ -501,7 +501,7 @@ class SaleOrderLine(models.Model): related_program_lines |= line.order_id.order_line.filtered(lambda l: l.product_id.id == related_program.discount_line_product_id.id) - line return super(SaleOrderLine, self | related_program_lines).unlink() - @api.depends('order_id.fiscal_position_id', 'tax_id.price_include', 'product_id.taxes_id.price_include') + @api.depends('product_id') def _compute_tax_id(self): reward_lines = self.filtered('is_reward_line') super(SaleOrderLine, self - reward_lines)._compute_tax_id() diff --git a/addons/sale_coupon/tests/test_program_numbers.py b/addons/sale_coupon/tests/test_program_numbers.py index 45628c631bf..b5659b497dc 100644 --- a/addons/sale_coupon/tests/test_program_numbers.py +++ b/addons/sale_coupon/tests/test_program_numbers.py @@ -6,7 +6,7 @@ from odoo.exceptions import UserError from odoo.tests import tagged -@tagged('post_install', '-at_install') +@tagged('post_install', '-at_install', 'program_numbers') class TestSaleCouponProgramNumbers(TestSaleCouponCommon): def setUp(self): @@ -188,6 +188,7 @@ class TestSaleCouponProgramNumbers(TestSaleCouponCommon): order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 1, "We should not get the reduction line since we dont have 320$ tax excluded (cabinet is 320$ tax included)") sol1.tax_id.price_include = False + sol1._compute_tax_id() order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 2, "We should now get the reduction line since we have 320$ tax included (cabinet is 320$ tax included)") # Name | Qty | price_unit | Tax | HTVA | TVAC | TVA | @@ -389,6 +390,7 @@ class TestSaleCouponProgramNumbers(TestSaleCouponCommon): self.assertEqual(len(order.order_line.ids), 12, "Order should contains 5 regular product lines, 3 free product lines and 4 discount lines (one for every tax)") # -- This is a test inside the test + order.order_line._compute_tax_id() self.assertEqual(order.amount_total, 1711, "Recomputing tax on sale order lines should not change total amount") self.assertEqual(order.amount_untaxed, 1435.46, "Recomputing tax on sale order lines should not change untaxed amount") self.assertEqual(len(order.order_line.ids), 12, "Recomputing tax on sale order lines should not change number of order line") diff --git a/addons/sale_management/models/sale_order.py b/addons/sale_management/models/sale_order.py index a3c3aabc18d..3f1e3f24d8a 100644 --- a/addons/sale_management/models/sale_order.py +++ b/addons/sale_management/models/sale_order.py @@ -50,7 +50,7 @@ class SaleOrder(models.Model): default['validity_date'] = fields.Date.context_today(self) + timedelta(self.sale_order_template_id.number_of_days) return super(SaleOrder, self).copy(default=default) - @api.depends('partner_id') + @api.depends('partner_id', 'sale_order_template_id') def _compute_note(self): super(SaleOrder, self)._compute_note() for order in self: diff --git a/addons/website_sale/tests/test_website_sale_product_attribute_value_config.py b/addons/website_sale/tests/test_website_sale_product_attribute_value_config.py index cf47621e3f1..51629cd40a5 100644 --- a/addons/website_sale/tests/test_website_sale_product_attribute_value_config.py +++ b/addons/website_sale/tests/test_website_sale_product_attribute_value_config.py @@ -6,7 +6,7 @@ from odoo.tests import tagged from odoo.addons.website.tools import MockRequest -@tagged('post_install', '-at_install') +@tagged('post_install', '-at_install', 'product_attribute') class TestWebsiteSaleProductAttributeValueConfig(TestSaleProductAttributeValueCommon): def test_get_combination_info(self): @@ -132,7 +132,7 @@ class TestWebsiteSaleProductAttributeValueConfig(TestSaleProductAttributeValueCo self.assertEqual(round(combination_info['price'], 2), 434.78, "434.78$ + 0% tax (mapped from fp 15% -> 0% for BE)") self.assertEqual(round(combination_info['list_price'], 2), 434.78, "434.78$ + 0% tax (mapped from fp 15% -> 0% for BE)") -@tagged('post_install', '-at_install') +@tagged('post_install', '-at_install', 'product_pricelist') class TestWebsiteSaleProductPricelist(TestSaleProductAttributeValueCommon): def test_cart_update_with_fpos(self): # We will test that the mapping of an 10% included tax by a 0% by a fiscal position is taken into account when updating the cart @@ -185,6 +185,7 @@ class TestWebsiteSaleProductPricelist(TestSaleProductAttributeValueCommon): self.assertEqual(round(sol.price_total), 110.0, "110$ with 10% included tax") so.pricelist_id = pricelist so.fiscal_position_id = fpos + sol._compute_tax_id() with MockRequest(self.env, website=current_website, sale_order_id=so.id): so._cart_update(product_id=test_product.product_variant_id.id, line_id=sol.id, set_qty=1) self.assertEqual(round(sol.price_total), 50, "100$ with 50% discount + 0% tax (mapped from fp 10% -> 0%)")