-
-
Notifications
You must be signed in to change notification settings - Fork 817
[19.0][OU-ADD] crm: Migration scripts #5706
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
+130
−1
Merged
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
Some comments aren't visible on the classic Files Changed page.
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
54 changes: 54 additions & 0 deletions
54
openupgrade_scripts/scripts/crm/19.0.1.9/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,54 @@ | ||
| # Copyright 2026 Tecnativa - Eduardo Ezerouali | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| def _migrate_lead_mobile(env): | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE crm_lead | ||
| SET phone = CONCAT(COALESCE(phone, ''), mobile) | ||
| WHERE COALESCE(mobile, '') != '' | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _load_data_pls_fields_param(env): | ||
| # New PLS fields added in v19. Merge them into the existing value instead of | ||
| # overwriting it, so a customized/removed `crm.pls_fields` param is preserved | ||
| new_fields = {"state_id", "country_id", "source_id", "lang_id", "tag_ids"} | ||
| param = env["ir.config_parameter"].sudo().get_param("crm.pls_fields") | ||
| if param: | ||
| current = set(param.split(",")) | ||
| merged = current | new_fields | ||
| env["ir.config_parameter"].sudo().set_param( | ||
| "crm.pls_fields", ",".join(sorted(merged)) | ||
| ) | ||
|
|
||
|
|
||
| def _load_data_stage_colors(env): | ||
| # Only color the default stages that still exist, | ||
| # skip any the user deleted in v18. | ||
| colors = { | ||
| "stage_lead1": 11, | ||
| "stage_lead2": 5, | ||
| "stage_lead3": 8, | ||
| "stage_lead4": 10, | ||
| } | ||
| for xml_id, color in colors.items(): | ||
| record = env.ref(f"crm.{xml_id}", raise_if_not_found=False) | ||
| if record: | ||
| record.color = color | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| # Do not load noupdate_changes.xml: every entry is problematic (deleted stages, | ||
| # customized pls param). the necessary changes are done manually in | ||
| # the _load_data_* functions below | ||
|
|
||
| openupgrade.m2o_to_x2m(env.cr, env["crm.stage"], "crm_stage", "team_ids", "team_id") | ||
| _load_data_stage_colors(env) | ||
| _load_data_pls_fields_param(env) | ||
| _migrate_lead_mobile(env) | ||
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,38 @@ | ||
| # Copyright 2026 Tecnativa - Eduardo Ezerouali | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| def _won_status_set(env): | ||
| # Precreate won_status and set with sql | ||
| openupgrade.add_columns( | ||
| env, | ||
| [ | ||
| ("crm.lead", "won_status", "selection", "pending", "crm_lead"), | ||
| ], | ||
|
pedrobaeza marked this conversation as resolved.
|
||
| ) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE crm_lead cl | ||
| SET won_status = 'won' | ||
| FROM crm_stage cs | ||
| WHERE cs.id = cl.stage_id | ||
| AND cs.is_won | ||
| AND cl.probability = 100 | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE crm_lead cl | ||
| SET won_status = 'lost' | ||
| WHERE NOT cl.active | ||
| AND cl.probability = 0 | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| _won_status_set(env) | ||
37 changes: 37 additions & 0 deletions
37
openupgrade_scripts/scripts/crm/19.0.1.9/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,37 @@ | ||
| ---Models in module 'crm'--- | ||
| ---Fields in module 'crm'--- | ||
| crm / crm.lead / commercial_partner_id (many2one): NEW relation: res.partner, hasdefault: compute, stored: False | ||
| # NOTHING TO DO | ||
|
|
||
| crm / crm.lead / mobile (char) : DEL | ||
| # DONE: pos-migration: if phone is empty and mobile not set phone with mobile and concatenate the mobile in the pone field in case both exist | ||
|
|
||
| crm / crm.lead / title (many2one) : DEL relation: res.partner.title | ||
| # NOTHING TO DO | ||
|
|
||
| crm / crm.lead / won_status (selection) : NEW selection_keys: ['lost', 'pending', 'won'], isfunction: function, stored | ||
| # DONE: pre-migration: pre-created column and set it to prevent massive computation | ||
|
|
||
| crm / crm.lead.scoring.frequency.field / color (integer) : NEW hasdefault: default | ||
| crm / crm.stage / color (integer) : NEW | ||
| # NOTHING TO DO | ||
|
|
||
| crm / crm.stage / rotting_threshold_days (integer): NEW hasdefault: default | ||
| # NOTHING TO DO: default is set to 0 to keep old behavoir | ||
|
|
||
| crm / crm.stage / team_id (many2one) : DEL relation: crm.team | ||
| crm / crm.stage / team_ids (many2many) : NEW relation: crm.team | ||
| # Done: post-migration: Transform m2o to m2m | ||
|
|
||
| crm / crm.team.member / assignment_domain_preferred (char): NEW | ||
| crm / res.users / target_sales_done (integer) : DEL | ||
| crm / res.users / target_sales_won (integer) : DEL | ||
| # NOTHING TO DO | ||
|
|
||
| ---XML records in module 'crm'--- | ||
| NEW ir.actions.act_window: crm.mail_followers_edit_action_from_lead | ||
| NEW ir.model.constraint: crm.constraint_crm_lead_create_date_team_id_idx | ||
| NEW ir.model.constraint: crm.constraint_crm_lead_default_order_idx | ||
| NEW ir.model.constraint: crm.constraint_crm_lead_user_id_team_id_type_index | ||
| DEL ir.ui.view: crm.crm_lead_partner_kanban_view | ||
| # NOTHING TO DO |
Oops, something went wrong.
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.