-
-
Notifications
You must be signed in to change notification settings - Fork 821
[17.0][OU-ADD] maintenance: Migration scripts #4654
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
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
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
38 changes: 38 additions & 0 deletions
38
openupgrade_scripts/scripts/maintenance/17.0.1.0/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,38 @@ | ||
| # Copyright 2024-2025 Tecnativa - Víctor Martínez | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
| from openupgradelib import openupgrade | ||
|
|
||
| _deleted_xml_records = ["maintenance.mail_alias_equipment"] | ||
|
|
||
|
|
||
| def _maintenance_plan(env): | ||
| """Compatibility with maintenance_plan, we convert the request and | ||
| the recurrence field the way it is done in core. | ||
| """ | ||
| if openupgrade.column_exists(env.cr, "maintenance_request", "maintenance_plan_id"): | ||
| # Update all the data of the linked requests | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """UPDATE maintenance_request mr | ||
| SET recurring_maintenance = True, | ||
| repeat_interval = COALESCE(mp.interval, 1), | ||
| repeat_unit = COALESCE(mp.interval_step, 'year'), | ||
| repeat_type='until', | ||
| repeat_until = ( | ||
| CURRENT_DATE + interval '' | ||
| || COALESCE(mp.maintenance_plan_horizon, 1) || ' ' | ||
| || COALESCE(mp.planning_step, 'year') | ||
| )::date | ||
| FROM maintenance_plan mp | ||
| WHERE mr.maintenance_plan_id = mp.id""", | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.load_data(env, "maintenance", "17.0.1.0/noupdate_changes.xml") | ||
| openupgrade.delete_records_safely_by_xml_id( | ||
| env, | ||
| _deleted_xml_records, | ||
| ) | ||
| _maintenance_plan(env) |
36 changes: 36 additions & 0 deletions
36
openupgrade_scripts/scripts/maintenance/17.0.1.0/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,36 @@ | ||
| # Copyright 2024 Tecnativa - Víctor Martínez | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| def _maintenance_request_company_id(env): | ||
| """We set the company_id value for requests that do not have it. | ||
| We get the value of what will be deductively most appropriate (equipment, team or | ||
| user). | ||
| """ | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """UPDATE maintenance_request AS request | ||
| SET company_id = equipment.company_id | ||
| FROM maintenance_equipment AS equipment | ||
| WHERE request.company_id IS NULL AND request.equipment_id = equipment.id""", | ||
| ) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """UPDATE maintenance_request AS request | ||
| SET company_id = team.company_id | ||
| FROM maintenance_team AS team | ||
| WHERE request.company_id IS NULL AND request.maintenance_team_id = team.id""", | ||
| ) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """UPDATE maintenance_request AS request | ||
| SET company_id = u.company_id | ||
| FROM res_users AS u | ||
| WHERE request.company_id IS NULL AND request.user_id = u.id""", | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| _maintenance_request_company_id(env) |
37 changes: 37 additions & 0 deletions
37
openupgrade_scripts/scripts/maintenance/17.0.1.0/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 'maintenance'--- | ||
| new model maintenance.mixin [abstract] | ||
| ---Fields in module 'maintenance'--- | ||
| maintenance / maintenance.equipment / activity_user_id (many2one) : not related anymore | ||
| maintenance / maintenance.equipment / activity_user_id (many2one) : now a function | ||
| maintenance / maintenance.equipment / expected_mtbf (integer) : NEW | ||
| maintenance / maintenance.equipment / maintenance_duration (float) : DEL | ||
| maintenance / maintenance.equipment / message_main_attachment_id (many2one): DEL relation: ir.attachment | ||
| maintenance / maintenance.equipment / next_action_date (date) : DEL | ||
| maintenance / maintenance.equipment / period (integer) : DEL | ||
| maintenance / maintenance.equipment.category / message_main_attachment_id (many2one): DEL relation: ir.attachment | ||
| maintenance / maintenance.request / activity_user_id (many2one) : not related anymore | ||
| maintenance / maintenance.request / activity_user_id (many2one) : now a function | ||
| # NOTHING TO DO | ||
| maintenance / maintenance.request / company_id (many2one) : now required | ||
| # DONE: pre-migration: Define the most appropriate value | ||
| maintenance / maintenance.request / instruction_google_slide (char): NEW | ||
| maintenance / maintenance.request / instruction_pdf (binary) : NEW attachment: True | ||
| maintenance / maintenance.request / instruction_text (html) : NEW | ||
| maintenance / maintenance.request / instruction_type (selection) : NEW selection_keys: ['google_slide', 'pdf', 'text'], hasdefault: default | ||
| maintenance / maintenance.request / message_main_attachment_id (many2one): DEL relation: ir.attachment | ||
| # NOTHING TO DO | ||
| maintenance / maintenance.request / recurring_maintenance (boolean): NEW hasdefault: compute | ||
| maintenance / maintenance.request / repeat_interval (integer) : NEW hasdefault: default | ||
| maintenance / maintenance.request / repeat_type (selection) : NEW selection_keys: ['forever', 'until'], hasdefault: default | ||
| maintenance / maintenance.request / repeat_unit (selection) : NEW selection_keys: ['day', 'month', 'week', 'year'], hasdefault: default | ||
| maintenance / maintenance.request / repeat_until (date) : NEW | ||
| # DONE: post-migration: maintenance_plan compatibility | ||
| ---XML records in module 'maintenance'--- | ||
| NEW ir.actions.act_window: maintenance.action_maintenance_configuration | ||
| DEL ir.cron: maintenance.maintenance_requests_cron | ||
| NEW ir.ui.menu: maintenance.menu_maintenance_config | ||
| NEW ir.ui.view: maintenance.maintenance_request_view_activity | ||
| NEW ir.ui.view: maintenance.res_config_settings_view_form | ||
| # NOTHING TO DO | ||
| DEL mail.alias: maintenance.mail_alias_equipment (noupdate) | ||
| # DONE: removed in post-migration | ||
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.