From 9bc5ccc940cac4c0d3f26589223c76c6594b70b3 Mon Sep 17 00:00:00 2001 From: Don Kendall Date: Wed, 8 Jul 2026 16:19:53 -0400 Subject: [PATCH] [OU-FIX] event: remap cancelled events onto Ended before dropping the Cancelled stage Assisted-by: Claude Fable 5 --- .../scripts/event/19.0.1.9/pre-migration.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/openupgrade_scripts/scripts/event/19.0.1.9/pre-migration.py b/openupgrade_scripts/scripts/event/19.0.1.9/pre-migration.py index e0b39b55a5c8..61065e8ace51 100644 --- a/openupgrade_scripts/scripts/event/19.0.1.9/pre-migration.py +++ b/openupgrade_scripts/scripts/event/19.0.1.9/pre-migration.py @@ -37,8 +37,51 @@ def event_event_badge_format(env): ) +def remap_cancelled_stage(env): + """ + 19.0 drops the Cancelled stage in favour of kanban_state='cancel'. + event.event.stage_id is ondelete='restrict', so remap cancelled events + onto the surviving Ended stage (flagged cancelled) before removing the + stage and its ir_model_data row. Pure SQL: event's models are not in + the registry during its own pre-migration. + """ + env.cr.execute( + """ + SELECT name, res_id FROM ir_model_data + WHERE module = 'event' AND model = 'event.stage' + AND name IN ('event_stage_cancelled', 'event_stage_done') + """ + ) + stages = dict(env.cr.fetchall()) + cancelled = stages.get("event_stage_cancelled") + done = stages.get("event_stage_done") + if not cancelled: + return + if done: + openupgrade.logged_query( + env.cr, + """ + UPDATE event_event + SET stage_id = %s, kanban_state = 'cancel' + WHERE stage_id = %s + """, + (done, cancelled), + ) + openupgrade.logged_query( + env.cr, "DELETE FROM event_stage WHERE id = %s", (cancelled,) + ) + openupgrade.logged_query( + env.cr, + """ + DELETE FROM ir_model_data + WHERE module = 'event' AND name = 'event_stage_cancelled' + """, + ) + + @openupgrade.migrate() def migrate(env, version): openupgrade.copy_columns(env.cr, _copy_columns) openupgrade.add_fields(env, _added_fields) event_event_badge_format(env) + remap_cancelled_stage(env)