From bd876de0f35d4c87bb6feddc6bf30cd261d0174c Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Wed, 24 Jun 2026 14:36:31 -0500 Subject: [PATCH] [OU-ADD] maintenance,stock_maintenance: Migration scripts --- docsource/modules180-190.rst | 4 +- .../maintenance/19.0.1.0/post-migration.py | 17 +++++++ .../maintenance/19.0.1.0/pre-migration.py | 49 +++++++++++++++++++ .../19.0.1.0/upgrade_analysis_work.txt | 33 +++++++++++++ .../19.0.1.0/upgrade_analysis_work.txt | 12 +++++ 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 openupgrade_scripts/scripts/maintenance/19.0.1.0/post-migration.py create mode 100644 openupgrade_scripts/scripts/maintenance/19.0.1.0/pre-migration.py create mode 100644 openupgrade_scripts/scripts/maintenance/19.0.1.0/upgrade_analysis_work.txt create mode 100644 openupgrade_scripts/scripts/stock_maintenance/19.0.1.0/upgrade_analysis_work.txt diff --git a/docsource/modules180-190.rst b/docsource/modules180-190.rst index e6116249b48e..90a9301e5df0 100644 --- a/docsource/modules180-190.rst +++ b/docsource/modules180-190.rst @@ -712,7 +712,7 @@ Module coverage 18.0 -> 19.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | mail_plugin | |No DB layout changes. | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| maintenance | | | +| maintenance |Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | marketing_card | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ @@ -1098,7 +1098,7 @@ Module coverage 18.0 -> 19.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | stock_landed_costs | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| |new| stock_maintenance | | | +| |new| stock_maintenance |Nothing to do | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | stock_picking_batch | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/maintenance/19.0.1.0/post-migration.py b/openupgrade_scripts/scripts/maintenance/19.0.1.0/post-migration.py new file mode 100644 index 000000000000..9613f8fc252a --- /dev/null +++ b/openupgrade_scripts/scripts/maintenance/19.0.1.0/post-migration.py @@ -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() diff --git a/openupgrade_scripts/scripts/maintenance/19.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/maintenance/19.0.1.0/pre-migration.py new file mode 100644 index 000000000000..60420c200e31 --- /dev/null +++ b/openupgrade_scripts/scripts/maintenance/19.0.1.0/pre-migration.py @@ -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; + """, + ) diff --git a/openupgrade_scripts/scripts/maintenance/19.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/maintenance/19.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..47ebae4a31c3 --- /dev/null +++ b/openupgrade_scripts/scripts/maintenance/19.0.1.0/upgrade_analysis_work.txt @@ -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 +# 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 diff --git a/openupgrade_scripts/scripts/stock_maintenance/19.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/stock_maintenance/19.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..f08dd242cdde --- /dev/null +++ b/openupgrade_scripts/scripts/stock_maintenance/19.0.1.0/upgrade_analysis_work.txt @@ -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