[IMP] sale: Don't recompute taxes on tax configuration change

This should be done manually
This commit is contained in:
Yannick Tivisse
2021-12-02 12:12:02 +01:00
parent 01557bf36e
commit fecff7119f
6 changed files with 14 additions and 11 deletions
+4 -2
View File
@@ -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 = []
+2 -4
View File
@@ -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:
+1 -1
View File
@@ -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()
@@ -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")
+1 -1
View File
@@ -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:
@@ -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%)")