-
-
Notifications
You must be signed in to change notification settings - Fork 819
[19.0][OU-ADD] maintenance,stock_maintenance: Migration scripts #5751
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
Open
carlos-lopez-tecnativa
wants to merge
1
commit into
OCA:19.0
Choose a base branch
from
Tecnativa:19.0-ou-add-maintenance
base: 19.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−2
Open
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
17 changes: 17 additions & 0 deletions
17
openupgrade_scripts/scripts/maintenance/19.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,17 @@ | ||
| # Copyright 2026 Tecnativa - Carlos Lopez | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.load_data(env, "maintenance", "19.0.1.0/noupdate_changes.xml") | ||
| openupgrade.delete_record_translations( | ||
| env.cr, | ||
| "maintenance", | ||
| ["mail_act_maintenance_request"], | ||
| ["summary"], | ||
| ) | ||
| model_id = env["ir.model"]._get_id("maintenance.equipment.category") | ||
| env["mail.alias"].search([("alias_parent_model_id", "=", model_id)]).unlink() |
49 changes: 49 additions & 0 deletions
49
openupgrade_scripts/scripts/maintenance/19.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,49 @@ | ||
| # Copyright 2026 Tecnativa - Carlos Lopez | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| _added_fields = [ | ||
| ( | ||
| "schedule_end", | ||
| "maintenance.request", | ||
| "maintenance_request", | ||
| "datetime", | ||
| None, | ||
| "maintenance", | ||
| ) | ||
| ] | ||
|
|
||
|
|
||
| def fill_maintenance_request_schedule_end(env): | ||
| """ | ||
| Fill the schedule_end field in maintenance.request records | ||
| based on schedule_date and duration. | ||
| If duration is not set, default to 1 hour. | ||
| """ | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE maintenance_request mr | ||
| SET schedule_end = schedule_date + INTERVAL '1 hour' * ( | ||
| CASE | ||
| WHEN mr.duration = 0 THEN 1 | ||
| ELSE COALESCE(mr.duration, 1) | ||
| END | ||
| ) | ||
| WHERE mr.schedule_date IS NOT NULL | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.add_fields(env, _added_fields) | ||
| fill_maintenance_request_schedule_end(env) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| ALTER TABLE maintenance_equipment_category | ||
| DROP CONSTRAINT IF EXISTS maintenance_equipment_category_alias_id_fkey; | ||
| """, | ||
| ) | ||
33 changes: 33 additions & 0 deletions
33
openupgrade_scripts/scripts/maintenance/19.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,33 @@ | ||
| ---Models in module 'maintenance'--- | ||
| ---Fields in module 'maintenance'--- | ||
| maintenance / maintenance.equipment / location (char) : DEL | ||
| # NOTHING TO DO: Odoo converts this field from char to many2one in the new stock_maintenance module. | ||
| # However, before this change, the location field was only informational, so we did not recreate it as a stock.location records. | ||
| # see https://github.com/odoo/odoo/pull/186032 | ||
|
|
||
| maintenance / maintenance.equipment / match_serial (boolean) : module is now 'stock_maintenance' ('maintenance') | ||
| # NOTHING TO DO: It was simply moved to the stock_maintenance module. | ||
|
|
||
| maintenance / maintenance.equipment.category / alias_id (many2one) : DEL relation: mail.alias, required | ||
| maintenance / maintenance.equipment.category / _inherits : DEL _inherits: {'mail.alias': 'alias_id'}, stored: False | ||
| maintenance / maintenance.equipment.category / message_follower_ids (one2many): DEL relation: mail.followers | ||
| maintenance / maintenance.equipment.category / message_ids (one2many) : DEL relation: mail.message | ||
|
carlos-lopez-tecnativa marked this conversation as resolved.
|
||
| # DONE: post-migration, delete the mail.alias records related to maintenance.equipment.category | ||
|
|
||
| maintenance / maintenance.team / _inherits : NEW _inherits: {'mail.alias': 'alias_id'}, stored: False | ||
| maintenance / maintenance.team / alias_id (many2one) : NEW relation: mail.alias, required | ||
| maintenance / maintenance.team / message_follower_ids (one2many): NEW relation: mail.followers | ||
| maintenance / maintenance.team / message_ids (one2many) : NEW relation: mail.message | ||
| # NOTHING TO DO: There are no direct relationships that allow translating data from maintenance.equipment.category to maintenance.team. | ||
| # See https://github.com/odoo/odoo/pull/196181 | ||
|
|
||
| maintenance / maintenance.request / duration (float) : now a function | ||
| # NOTHING TO DO: The field is now computed, but the underlying logic remains the same. The existing data is preserved. | ||
|
|
||
| maintenance / maintenance.request / schedule_end (datetime) : NEW hasdefault: compute | ||
| # DONE: pre-migration precreated and populated based on schedule_date and duration when duration was set. | ||
| # Otherwise, one hour was added to schedule_date, matching Odoo's field computation logic. | ||
|
|
||
| ---XML records in module 'maintenance'--- | ||
| NEW res.groups.privilege: maintenance.res_groups_privilege_maintenance | ||
| # NOTHING TO DO: New feature | ||
12 changes: 12 additions & 0 deletions
12
openupgrade_scripts/scripts/stock_maintenance/19.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,12 @@ | ||
| ---Models in module 'stock_maintenance'--- | ||
| ---Fields in module 'stock_maintenance'--- | ||
| stock_maintenance / maintenance.equipment / location_id (many2one) : NEW relation: stock.location | ||
| # NOTHING TO DO: New feature | ||
|
|
||
| stock_maintenance / maintenance.equipment / match_serial (boolean) : previously in module maintenance | ||
| # NOTHING TO DO: It was simply moved to the maintenance module. | ||
|
|
||
| ---XML records in module 'stock_maintenance'--- | ||
| NEW ir.ui.view: stock_maintenance.maintenance_stock_equipment_view_form | ||
| NEW ir.ui.view: stock_maintenance.stock_location_form_maintenance_equipments | ||
| # NOTHING TO DO: Handled by ORM |
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.