summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorVictor Feyens <vfe@odoo.com>2020-03-05 17:55:07 +0000
committerVictor Feyens <vfe@odoo.com>2020-03-05 19:17:17 +0000
commit917e7a1a9b2c4c131697399fcd03dbf125f3be79 (patch)
treef12a9a53816aab7df9ccd9d00a3444746e4db832 /addons
parent5ae6f02e45168ef95d65c1956cea8b90218d8941 (diff)
[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>
Diffstat (limited to 'addons')
-rw-r--r--addons/product/models/product_template.py3
-rw-r--r--addons/product/tests/test_variants.py22
2 files changed, 25 insertions, 0 deletions
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):