-
-
Notifications
You must be signed in to change notification settings - Fork 785
[18.0][OU-ADD] product #4839
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
Merged
Merged
[18.0][OU-ADD] product #4839
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
openupgrade_scripts/scripts/product/18.0.1.2/post-migration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Copyright 2025 Hunki Enterprises BV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade, openupgrade_180 | ||
|
|
||
|
|
||
| def product_document_sequence(env): | ||
| """ | ||
| Set sequence matching previous name only ordering | ||
| """ | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE product_document | ||
| SET sequence=sequence.sequence | ||
| FROM | ||
| ( | ||
| SELECT | ||
| product_document.id, row_number() OVER ( | ||
| PARTITION BY ir_attachment.res_id, ir_attachment.res_model | ||
| ORDER BY ir_attachment.name | ||
| ) sequence | ||
| FROM | ||
| product_document | ||
| JOIN ir_attachment | ||
| ON product_document.ir_attachment_id=ir_attachment.id | ||
| ) sequence | ||
| WHERE | ||
| sequence.id=product_document.id | ||
| AND product_document.sequence IS NULL | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def product_template_is_favorite(env): | ||
| """ | ||
| Set is_favorite flag based on priority | ||
| """ | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE | ||
| product_template | ||
| SET is_favorite = (priority IS NOT NULL AND priority != '0') | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def res_partner_specific_property_product_pricelist(env): | ||
| """ | ||
| Get value for specific_property_product_pricelist from v17 | ||
| property_product_pricelist | ||
| """ | ||
| old_field = env.ref("product.field_res_partner__property_product_pricelist") | ||
| openupgrade_180.convert_company_dependent( | ||
| env, | ||
| "res.partner", | ||
| "specific_property_product_pricelist", | ||
| old_field_id=old_field.id, | ||
| ) | ||
| # convert_company_dependent might have created ir.default entries, wipe them | ||
| new_field = env.ref( | ||
| "product.field_res_partner__specific_property_product_pricelist" | ||
| ) | ||
| env["ir.default"].search([("field_id", "=", new_field.id)]).unlink() | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| product_document_sequence(env) | ||
| product_template_is_favorite(env) | ||
| res_partner_specific_property_product_pricelist(env) | ||
| openupgrade_180.convert_company_dependent(env, "product.product", "standard_price") |
73 changes: 73 additions & 0 deletions
73
openupgrade_scripts/scripts/product/18.0.1.2/pre-migration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Copyright 2025 Hunki Enterprises BV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| xmlid_renames = [ | ||
| ("product.group_discount_per_so_line", "sale.group_discount_per_so_line"), | ||
| ] | ||
|
|
||
| column_creates = [ | ||
| ("product.attribute", "active", "boolean", "TRUE"), | ||
| ("product.attribute.value", "active", "boolean", "TRUE"), | ||
| ("product.pricelist.item", "display_applied_on", "char"), | ||
| ("product.pricelist.item", "price_markup", "float"), | ||
| ] | ||
|
|
||
|
|
||
| def rename_pos_models(env): | ||
| """ | ||
| pos.combo and pos.combo.line have been moved to product from point_of_sale and | ||
| renamed to product.combo and product.combo.item respectively | ||
| """ | ||
| if not openupgrade.table_exists(env.cr, "pos_combo"): | ||
| return | ||
|
|
||
| openupgrade.rename_tables( | ||
| env.cr, | ||
| [ | ||
| ("pos_combo", "product_combo"), | ||
| ("pos_combo_line", "product_combo_item"), | ||
| ], | ||
| ) | ||
| openupgrade.rename_models( | ||
| env.cr, | ||
| [ | ||
| ("pos.combo", "product.combo"), | ||
| ("pos.combo.line", "product.combo.item"), | ||
| ], | ||
| ) | ||
| openupgrade.rename_fields( | ||
| env, | ||
| [ | ||
| ("product.combo", "product_combo", "combo_line_ids", "combo_item_ids"), | ||
| ("product.combo.item", "product_combo_item", "combo_price", "extra_price"), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| def fill_product_pricelist_item_columns(env): | ||
| """ | ||
| Set display_applied_on to '2_product_category' if applied_on is | ||
| '2_product_category', else '1_product' | ||
| Set price_markup = -price_discount | ||
| """ | ||
| env.cr.execute( | ||
| """ | ||
| UPDATE product_pricelist_item | ||
| SET | ||
| display_applied_on=CASE | ||
| WHEN applied_on='2_product_category' THEN '2_product_category' | ||
| ELSE '1_product' | ||
| END, | ||
| price_markup=-price_discount | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.rename_xmlids(env.cr, xmlid_renames) | ||
| openupgrade.add_columns(env, column_creates) | ||
| fill_product_pricelist_item_columns(env) | ||
| rename_pos_models(env) | ||
106 changes: 106 additions & 0 deletions
106
openupgrade_scripts/scripts/product/18.0.1.2/upgrade_analysis_work.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| ---Models in module 'product'--- | ||
| new model product.combo | ||
| new model product.combo.item | ||
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # DONE: pre-migration: rename models and fields from point_of_sale models if installed | ||
|
|
||
| new model update.product.attribute.value [transient] | ||
| # NOTHING TO DO: new functionality | ||
|
|
||
| ---Fields in module 'product'--- | ||
| product / product.attribute / active (boolean) : NEW hasdefault: default | ||
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # DONE: added in pre-migration | ||
|
|
||
| product / product.attribute / template_value_ids (one2many) : NEW relation: product.template.attribute.value | ||
| # NOTHING TO DO | ||
|
|
||
| product / product.attribute.value / active (boolean) : NEW hasdefault: default | ||
| # DONE: added in pre-migration | ||
|
|
||
| product / product.category / message_follower_ids (one2many): NEW relation: mail.followers | ||
| product / product.category / message_ids (one2many) : NEW relation: mail.message | ||
| product / product.combo / combo_item_ids (one2many) : NEW relation: product.combo.item | ||
| product / product.combo / company_id (many2one) : NEW relation: res.company | ||
| product / product.combo / name (char) : NEW required | ||
| product / product.combo / sequence (integer) : NEW hasdefault: default | ||
| product / product.combo.item / combo_id (many2one) : NEW relation: product.combo, required | ||
| product / product.combo.item / company_id (many2one) : NEW relation: res.company, isrelated: related, stored | ||
| product / product.combo.item / extra_price (float) : NEW hasdefault: default | ||
| product / product.combo.item / product_id (many2one) : NEW relation: product.product, required | ||
| # NOTHING TO DO | ||
|
|
||
| product / product.document / _order : _order is now 'sequence, name' ('name') | ||
| # DONE: see product.document#sequence below | ||
|
|
||
| product / product.document / sequence (integer) : NEW hasdefault: default | ||
| # DONE: post-migration: create sequence matching name | ||
|
|
||
| product / product.pricelist / _order : _order is now 'sequence, id, name' ('sequence asc, id asc') | ||
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # NOTHING TO DO: change doesn't actually affect ordering | ||
|
|
||
| product / product.pricelist / discount_policy (selection) : DEL required, selection_keys: ['with_discount', 'without_discount'] | ||
| product / product.pricelist.item / display_applied_on (selection): NEW required, selection_keys: ['1_product', '2_product_category'], hasdefault: default | ||
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| product / product.pricelist.item / price_markup (float) : NEW isfunction: function, stored | ||
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # DONE: added and filled in pre-migration | ||
|
|
||
| product / product.product / _order : _order is now 'is_favorite desc, default_code, name, id' ('priority desc, default_code, name, id') | ||
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # NOTHING TO DO: see product.template#is_favorite below | ||
|
|
||
| product / product.product / combo_ids (many2many) : previously in module point_of_sale | ||
| # DONE: see product.combo above | ||
|
|
||
| product / product.product / service_tracking (selection) : previously in module sale_project | ||
| # NOTHING TO DO | ||
|
|
||
| product / product.product / standard_price (float) : needs conversion to v18-style company dependent | ||
| # DONE: post-migration | ||
|
|
||
| product / product.product / type (selection) : now required | ||
| # NOTHING TO DO: had a default in previous version already | ||
|
|
||
| product / product.tag / _order : _order is now 'sequence, id' ('id') | ||
| product / product.tag / sequence (integer) : NEW hasdefault: default | ||
| product / product.template / _order : _order is now 'is_favorite desc, name' ('priority desc, name') | ||
MiquelRForgeFlow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # NOTHING TO DO: ordering stays the same | ||
|
|
||
| product / product.template / combo_ids (many2many) : previously in module point_of_sale | ||
| # NOTHING TO DO: see product.combo above | ||
|
|
||
| product / product.template / detailed_type (selection) : DEL required, selection_keys: ['consu', 'service'] | ||
| # NOTHING TO DO, might need followup in subsequent addons | ||
|
|
||
| product / product.template / is_favorite (boolean) : NEW | ||
| product / product.template / priority (selection) : DEL selection_keys: ['0', '1'] | ||
| # DONE: set is_favorite flag based on priority | ||
|
|
||
| product / product.template / service_tracking (selection) : previously in module sale_project | ||
| product / product.template / type (selection) : now required | ||
|
Contributor
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. I am sure this doesn't happen, but maybe just in case, we should fill if empty using detailed_type |
||
| product / product.template / type (selection) : selection_keys is now '['combo', 'consu', 'service']' ('['consu', 'service']') | ||
| # NOTHING TO DO | ||
|
|
||
| product / res.partner / specific_property_product_pricelist (many2one): NEW relation: product.pricelist | ||
| # DONE: post-migration: convert from v17 property res.partner#property_product_pricelist | ||
|
|
||
| ---XML records in module 'product'--- | ||
| NEW ir.actions.act_window: product.product_combo_action | ||
| NEW ir.model.access: product.access_product_combo_item_manager | ||
| NEW ir.model.access: product.access_product_combo_item_user | ||
| NEW ir.model.access: product.access_product_combo_manager | ||
| NEW ir.model.access: product.access_product_combo_user | ||
| NEW ir.model.access: product.access_update_product_attribute_value_manager | ||
| DEL ir.model.constraint: product.constraint_product_attribute_value_value_company_uniq | ||
| NEW ir.rule: product.product_combo_comp_rule (noupdate) | ||
| NEW ir.ui.view: product.product_attribute_search | ||
| NEW ir.ui.view: product.product_combo_view_form | ||
| NEW ir.ui.view: product.product_combo_view_tree | ||
| NEW ir.ui.view: product.product_packaging_search_view | ||
| NEW ir.ui.view: product.product_product_view_form_normalized | ||
| NEW ir.ui.view: product.product_template_attribute_line_view_tree | ||
| NEW ir.ui.view: product.update_product_attribute_value_form | ||
| NEW res.groups: product.group_product_manager | ||
| # NOTHING TO DO | ||
|
|
||
| DEL res.groups: product.group_discount_per_so_line [renamed to sale module] | ||
| # DONE: pre-migration: moved xmlid to sale | ||
|
|
||
| DEL res.groups: product.group_sale_pricelist | ||
| # NOTHING TO DO | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| env = locals().get("env") | ||
| # set specific pricelist | ||
| pricelist_main = env["product.pricelist"].create({"name": "Pricelist for main company"}) | ||
| company = env["res.company"].create({"name": "Product migration test company"}) | ||
| pricelist = ( | ||
| env["product.pricelist"] | ||
| .with_company(company) | ||
| .create({"name": "Pricelist for demo company"}) | ||
| ) | ||
| partner = env.ref("base.user_demo").partner_id | ||
|
|
||
| partner.property_product_pricelist = pricelist_main | ||
| partner.with_company(company).property_product_pricelist = pricelist | ||
|
|
||
| env.cr.commit() |
30 changes: 30 additions & 0 deletions
30
openupgrade_scripts/scripts/product/tests/test_migration.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from odoo.tests import TransactionCase | ||
|
|
||
| from odoo.addons.openupgrade_framework import openupgrade_test | ||
|
|
||
|
|
||
| @openupgrade_test | ||
| class TestProductMigration(TransactionCase): | ||
| def test_pricelist(self): | ||
| partner = self.env.ref("base.user_demo").partner_id | ||
| company = self.env["res.company"].search( | ||
| [ | ||
| ("name", "=", "Product migration test company"), | ||
| ] | ||
| ) | ||
| pricelist_main = self.env["product.pricelist"].search( | ||
| [ | ||
| ("name", "=", "Pricelist for main company"), | ||
| ] | ||
| ) | ||
| pricelist = self.env["product.pricelist"].search( | ||
| [ | ||
| ("name", "=", "Pricelist for demo company"), | ||
| ] | ||
| ) | ||
| self.assertTrue(company) | ||
| self.assertTrue(pricelist) | ||
| self.assertEqual(partner.property_product_pricelist, pricelist_main) | ||
| self.assertEqual( | ||
| partner.with_company(company).property_product_pricelist, pricelist | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.