Repository navigation
[18.0][OU-FIX] product: convert dead type defaults #6113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|---|---|---|
| @@ -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") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")) | ||
There was a problem hiding this comment.
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.