Skip to content

Commit

Permalink
[MIG] product_variant_sale_price: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbitJon-S73 committed Jun 22, 2023
1 parent 5ba7c7f commit 4e0a63c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion product_variant_sale_price/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Product Variant Sale Price",
"summary": "Allows to write fixed prices in product variants",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Product Management",
"website": "https://github.com/OCA/product-variant",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
Expand Down
25 changes: 12 additions & 13 deletions product_variant_sale_price/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ def _update_fix_price(self, vals):
if "list_price" in vals:
self.mapped("product_variant_ids").write({"fix_price": vals["list_price"]})

@api.model
def create(self, vals):
product_tmpl = super().create(vals)
product_tmpl._update_fix_price(vals)
@api.model_create_multi
def create(self, vals_list):
product_tmpl = super().create(vals_list)
for prod, vals in zip(product_tmpl, vals_list):
prod._update_fix_price(vals)
return product_tmpl

def write(self, vals):
Expand All @@ -34,27 +35,25 @@ def _compute_lst_price(self):
uom_model = self.env["uom.uom"]
for product in self:
price = product.fix_price or product.list_price
if "uom" in self.env.context:
price = product.uom_id._compute_price(
price, uom_model.browse(self.env.context["uom"])
)
if self.env.context.get("uom"):
context_uom = uom_model.browse(self.env.context["uom"])
price = product.uom_id._compute_price(price, context_uom)
product.lst_price = price

def _compute_list_price(self):
uom_model = self.env["uom.uom"]
for product in self:
price = product.fix_price or product.product_tmpl_id.list_price
if "uom" in self.env.context:
price = product.uom_id._compute_price(
price, uom_model.browse(self.env.context["uom"])
)
if self.env.context.get("uom"):
context_uom = uom_model.browse(self.env.context["uom"])
price = product.uom_id._compute_price(price, context_uom)
product.list_price = price

def _inverse_product_lst_price(self):
uom_model = self.env["uom.uom"]
for product in self:
vals = {}
if "uom" in self.env.context:
if self.env.context.get("uom"):
vals["fix_price"] = product.uom_id._compute_price(
product.lst_price, uom_model.browse(self.env.context["uom"])
)
Expand Down
6 changes: 3 additions & 3 deletions product_variant_sale_price/tests/test_product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def test_post_init_hook(self):
)

# Flush the records to DB before direct SQL
self.product_blue.flush()
self.product_red.flush()
self.product_blue.env.flush_all()
self.product_red.env.flush_all()

set_sale_price_on_variant(self.cr, None, self.product_template.id)
self.product_template.product_variant_ids.invalidate_cache()
self.product_template.product_variant_ids.invalidate_recordset()
self.assertEqual(
self.product_template.list_price + 100.00, self.product_blue.lst_price
)
Expand Down
6 changes: 6 additions & 0 deletions setup/product_variant_sale_price/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 4e0a63c

Please sign in to comment.