Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions openupgrade_scripts/scripts/product/18.0.1.2/end-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2026 Binhex <https://www.binhex.cloud>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
"""Turn the dead v14-17 'product' type default into consu + storable."""
defaults = env["ir.default"]
storable = env["ir.model.fields"]._get("product.template", "is_storable")
env.cr.execute(
"""
SELECT user_id, company_id, condition
FROM ir_default
WHERE field_id = %s AND json_value = '"product"'
""",
(env.ref("product.field_product_template__type").id,),
)
for user_id, company_id, condition in env.cr.fetchall():
scope = dict(user_id=user_id, company_id=company_id, condition=condition)
# ir.default.set() invalidates the defaults cache, raw SQL would not
defaults.set("product.template", "type", "consu", **scope)
if storable:
defaults.set("product.template", "is_storable", True, **scope)
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ product / product.template / priority (selection) : DEL se
product / product.template / service_tracking (selection) : previously in module sale_project
product / product.template / type (selection) : now required
product / product.template / type (selection) : selection_keys is now '['combo', 'consu', 'service']' ('['consu', 'service']')
# NOTHING TO DO
# DONE: end-migration: rewrite the dead 'product' type default to 'consu' + is_storable

product / res.partner / specific_property_product_pricelist (many2one): NEW relation: product.pricelist
# DONE: post-migration: convert from v17 property res.partner#property_product_pricelist
Expand Down
2 changes: 2 additions & 0 deletions openupgrade_scripts/scripts/product/tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
partner.property_product_pricelist = pricelist_main
partner.with_company(company).property_product_pricelist = pricelist

env["ir.default"].set("product.template", "type", "product")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a comment to say it's a value set for test with pre-18 behaviour.


env.cr.commit()
9 changes: 8 additions & 1 deletion openupgrade_scripts/scripts/product/tests/test_migration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from odoo.tests import TransactionCase
from odoo.tests import TransactionCase, tagged

from odoo.addons.openupgrade_framework import openupgrade_test


@openupgrade_test
@tagged("post_install", "-at_install")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would modify test's condition of test_pricelist(), it's better to add a new class for the new test.

class TestProductMigration(TransactionCase):
def test_pricelist(self):
partner = self.env.ref("base.user_demo").partner_id
Expand All @@ -28,3 +29,9 @@ def test_pricelist(self):
self.assertEqual(
partner.with_company(company).property_product_pricelist, pricelist
)

def test_product_type_defaults(self):
default = self.env["ir.default"]
self.assertEqual(default._get("product.template", "type"), "consu")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you could simply create a product.template and check its type and is_storable field.

if "is_storable" in self.env["product.template"]._fields:
self.assertTrue(default._get("product.template", "is_storable"))
Loading