From 25004a958d699a1d85295e7b0213d29bd41ce3ee Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Wed, 9 Oct 2019 09:05:48 +0000 Subject: [PATCH] [FIX] sale: small cleanup of line computations Initially a forward-port of 5aecd365d7b, which needed f407e60ad680371 to work. The do_in_onchange was removed inbetween, but it is not needed anymore here. The issue was caused by the fact that the cache values given for each environment, whereas in the new ORM the values are now shared across all. The other potential issue caught by this test was that the company of the taxes could be incorrect. This is problematic for the end user, since relational that violates inter-company rules mean that they won't be able to read or write the records without sudo. However the model now has _check_company_auto, handled by the ORM, so the issue should not arise anymore. closes odoo/odoo#38543 X-original-commit: 30cf4b37327ac86584c3025d8fa11b4094f9cbda Signed-off-by: Nans Lefebvre (len) --- addons/sale/models/sale.py | 3 +-- addons/sale/tests/test_sale_order.py | 20 ++------------------ 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index bf35fcbc35c..9e3987e4089 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -1064,8 +1064,7 @@ class SaleOrderLine(models.Model): for line in self: 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 - line_company_id = line.company_id or line.order_id.company_id - taxes = line.product_id.taxes_id.filtered(lambda r: not line_company_id or r.company_id == line_company_id) + 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 @api.model diff --git a/addons/sale/tests/test_sale_order.py b/addons/sale/tests/test_sale_order.py index bb3223b0e7f..ddf5c865cd2 100644 --- a/addons/sale/tests/test_sale_order.py +++ b/addons/sale/tests/test_sale_order.py @@ -265,23 +265,13 @@ class TestSaleOrder(TestCommonSaleNoChart): 'Taxes should be applied') def test_so_create_multicompany(self): - # Preparing test Data + """Check that only taxes of the right company are applied on the lines.""" user_demo = self.env.ref('base.user_demo') company_1 = self.env.ref('base.main_company') company_2 = self.env['res.company'].create({ 'name': 'company 2', 'parent_id': company_1.id, }) - user_demo.write({ - 'groups_id': [(4, self.env.ref('sales_team.group_sale_manager').id, False)], - 'company_ids': [(6, False, [company_1.id])], - 'company_id': company_1.id, - }) - - so_partner = self.env.ref('base.res_partner_2') - so_partner.write({ - 'property_account_position_id': False, - }) tax_company_1 = self.env['account.tax'].create({ 'name': 'T1', @@ -300,16 +290,10 @@ class TestSaleOrder(TestCommonSaleNoChart): 'taxes_id': [(6, False, [tax_company_1.id, tax_company_2.id])], }) - # Use case so_1 = self.env['sale.order'].with_user(user_demo.id).create({ - 'partner_id': so_partner.id, + 'partner_id': self.env.ref('base.res_partner_2').id, 'company_id': company_1.id, }) - so_1.invalidate_cache() - - # This is what is done when importing the csv lines (on sale.order): - # id,order_line/product_id - # __export__.sale_order_37_1bb960ba,Product name so_1.write({ 'order_line': [(0, False, {'product_id': product_shared.product_variant_id.id, 'order_id': so_1.id})], })