[FIX] product: standard_price depends on company context

Product templates standard_price (cost) is company_dependent,
because the product_product standard_price is company dependent.

closes odoo/odoo#47041

Forward-port-of: odoo/odoo#46841
X-original-commit: 30ee9f1ac411aca9c2bf2158fca9be7db743616d
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2020-03-05 19:17:17 +00:00
parent 5ae6f02e45
commit 917e7a1a9b
2 changed files with 25 additions and 0 deletions
@@ -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
+22
View File
@@ -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):