Skip to content

Commit 4e0a63c

Browse files
committed
[MIG] product_variant_sale_price: Migration to 16.0
1 parent 5ba7c7f commit 4e0a63c

File tree

5 files changed

+23
-17
lines changed

5 files changed

+23
-17
lines changed

product_variant_sale_price/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "Product Variant Sale Price",
77
"summary": "Allows to write fixed prices in product variants",
8-
"version": "15.0.1.0.0",
8+
"version": "16.0.1.0.0",
99
"category": "Product Management",
1010
"website": "https://github.com/OCA/product-variant",
1111
"author": "Tecnativa, " "Odoo Community Association (OCA)",

product_variant_sale_price/models/product_product.py

+12-13
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ def _update_fix_price(self, vals):
1111
if "list_price" in vals:
1212
self.mapped("product_variant_ids").write({"fix_price": vals["list_price"]})
1313

14-
@api.model
15-
def create(self, vals):
16-
product_tmpl = super().create(vals)
17-
product_tmpl._update_fix_price(vals)
14+
@api.model_create_multi
15+
def create(self, vals_list):
16+
product_tmpl = super().create(vals_list)
17+
for prod, vals in zip(product_tmpl, vals_list):
18+
prod._update_fix_price(vals)
1819
return product_tmpl
1920

2021
def write(self, vals):
@@ -34,27 +35,25 @@ def _compute_lst_price(self):
3435
uom_model = self.env["uom.uom"]
3536
for product in self:
3637
price = product.fix_price or product.list_price
37-
if "uom" in self.env.context:
38-
price = product.uom_id._compute_price(
39-
price, uom_model.browse(self.env.context["uom"])
40-
)
38+
if self.env.context.get("uom"):
39+
context_uom = uom_model.browse(self.env.context["uom"])
40+
price = product.uom_id._compute_price(price, context_uom)
4141
product.lst_price = price
4242

4343
def _compute_list_price(self):
4444
uom_model = self.env["uom.uom"]
4545
for product in self:
4646
price = product.fix_price or product.product_tmpl_id.list_price
47-
if "uom" in self.env.context:
48-
price = product.uom_id._compute_price(
49-
price, uom_model.browse(self.env.context["uom"])
50-
)
47+
if self.env.context.get("uom"):
48+
context_uom = uom_model.browse(self.env.context["uom"])
49+
price = product.uom_id._compute_price(price, context_uom)
5150
product.list_price = price
5251

5352
def _inverse_product_lst_price(self):
5453
uom_model = self.env["uom.uom"]
5554
for product in self:
5655
vals = {}
57-
if "uom" in self.env.context:
56+
if self.env.context.get("uom"):
5857
vals["fix_price"] = product.uom_id._compute_price(
5958
product.lst_price, uom_model.browse(self.env.context["uom"])
6059
)

product_variant_sale_price/tests/test_product_product.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def test_post_init_hook(self):
6767
)
6868

6969
# Flush the records to DB before direct SQL
70-
self.product_blue.flush()
71-
self.product_red.flush()
70+
self.product_blue.env.flush_all()
71+
self.product_red.env.flush_all()
7272

7373
set_sale_price_on_variant(self.cr, None, self.product_template.id)
74-
self.product_template.product_variant_ids.invalidate_cache()
74+
self.product_template.product_variant_ids.invalidate_recordset()
7575
self.assertEqual(
7676
self.product_template.list_price + 100.00, self.product_blue.lst_price
7777
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../product_variant_sale_price
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)