diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 1fcc4b75bf4..eee7ae100b3 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -217,8 +217,11 @@ class ProductTemplate(models.Model): else: self.write({'list_price': self.price}) + @api.depends_context('company') @api.depends('product_variant_ids', 'product_variant_ids.standard_price') def _compute_standard_price(self): + # Depends on force_company context because standard_price is company_dependent + # on the product_product unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1) for template in unique_variants: template.standard_price = template.product_variant_ids.standard_price diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py index fb73867c2bb..89009f113e6 100644 --- a/addons/product/tests/test_variants.py +++ b/addons/product/tests/test_variants.py @@ -210,6 +210,28 @@ class TestVariants(common.TestProductCommon): self.assertEqual(variant_copy.name, 'Test Copy (copy) (copy)') self.assertEqual(len(variant_copy.product_variant_ids), 2) + def test_standard_price(self): + """ Ensure template values are correctly (re)computed depending on the context """ + one_variant_product = self.product_1 + self.assertEqual(one_variant_product.product_variant_count, 1) + + company_a = self.env.company + company_b = self.env['res.company'].create({'name': 'CB', 'currency_id': self.env.ref('base.VEF').id}) + + self.assertEqual(one_variant_product.cost_currency_id, company_a.currency_id) + self.assertEqual(one_variant_product.with_company(company_b).cost_currency_id, company_b.currency_id) + + one_variant_template = one_variant_product.product_tmpl_id + self.assertEqual(one_variant_product.standard_price, one_variant_template.standard_price) + one_variant_product.with_company(company_b).standard_price = 500.0 + self.assertEqual( + one_variant_product.with_company(company_b).standard_price, + one_variant_template.with_company(company_b).standard_price + ) + self.assertEqual( + 500.0, + one_variant_template.with_company(company_b).standard_price + ) class TestVariantsNoCreate(common.TestProductCommon):