From 7dd2bae4842228f12c9976a45cb394bc82cfe395 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Mon, 19 Jul 2021 21:18:10 +0200 Subject: [PATCH] [FIX+IMP] event: Finish migration scripts * Refactor stages code * Don't assign "Booked" stage, as it can't be determined by previous state * Missing XML-ID renaming --- .../scripts/event/14.0.1.3/post-migration.py | 58 ++++--------------- .../scripts/event/14.0.1.3/pre-migration.py | 8 ++- .../event/14.0.1.3/upgrade_analysis_work.txt | 20 +++---- 3 files changed, 28 insertions(+), 58 deletions(-) diff --git a/openupgrade_scripts/scripts/event/14.0.1.3/post-migration.py b/openupgrade_scripts/scripts/event/14.0.1.3/post-migration.py index de025f786039..f51646beb7de 100644 --- a/openupgrade_scripts/scripts/event/14.0.1.3/post-migration.py +++ b/openupgrade_scripts/scripts/event/14.0.1.3/post-migration.py @@ -1,55 +1,21 @@ # Copyright 2021 ForgeFlow S.L. +# Copyright 2021 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openupgradelib import openupgrade def map_event_event_states_to_stages(env): - openupgrade.logged_query( - env.cr, - """ - UPDATE event_event event - SET stage_id = stage.id - FROM event_stage stage - WHERE stage.name = 'New' AND event.state = 'draft'""", - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE event_event event - SET stage_id = stage.id - FROM event_stage stage, event_event event2 - LEFT JOIN event_registration evr ON evr.event_id = event2.id - WHERE stage.name = 'Booked' AND event.state = 'confirm' - AND evr.id IS NULL OR evr.state IN ('draft', 'cancel') - AND event.id = event2.id""", - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE event_event event - SET stage_id = stage.id - FROM event_stage stage, event_event event2 - JOIN event_registration evr ON evr.event_id = event2.id - WHERE stage.name = 'Announced' AND event.state = 'confirm' - AND evr.state IN ('open', 'done') - AND event.id = event2.id""", - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE event_event event - SET stage_id = stage.id - FROM event_stage stage - WHERE stage.name = 'Ended' AND event.state = 'done'""", - ) - openupgrade.logged_query( - env.cr, - """ - UPDATE event_event event - SET stage_id = stage.id - FROM event_stage stage - WHERE stage.name = 'Cancelled' AND event.state = 'cancel'""", - ) + def _map_state_to_stage(state, stage_xmlid): + query = """ + UPDATE event_event event SET stage_id = imd.res_id + FROM ir_model_data imd + WHERE imd.module = 'event' AND imd.name = %s AND event.state = %s""" + openupgrade.logged_query(env.cr, query, (stage_xmlid, state)) + + _map_state_to_stage("draft", "event_stage_new") + _map_state_to_stage("done", "event_stage_done") + _map_state_to_stage("cancel", "event_stage_cancelled") + _map_state_to_stage("confirm", "event_stage_announced") @openupgrade.migrate() diff --git a/openupgrade_scripts/scripts/event/14.0.1.3/pre-migration.py b/openupgrade_scripts/scripts/event/14.0.1.3/pre-migration.py index 5296fc5cbfe8..6f4a4aead836 100644 --- a/openupgrade_scripts/scripts/event/14.0.1.3/pre-migration.py +++ b/openupgrade_scripts/scripts/event/14.0.1.3/pre-migration.py @@ -16,7 +16,11 @@ ( "event_sale.access_event_event_ticket_user", "event.access_event_event_ticket_user", - ) + ), + ( + "event_sale.access_event_event_ticket_admin", + "event.access_event_event_ticket_manager", + ), ] @@ -66,7 +70,7 @@ def migrate(env, version): openupgrade.rename_fields(env, _field_renames) if openupgrade.table_exists(env.cr, "event_event_ticket"): openupgrade.rename_fields(env, _field_renames_event_sale) - openupgrade.rename_xmlids(env.cr, _xmlid_renames_event_sale) + openupgrade.rename_xmlids(env.cr, _xmlid_renames_event_sale) rename_event_event_seats(env) fast_fill_kanban_state(env) avoid_default_in_event_event_stage_id(env) diff --git a/openupgrade_scripts/scripts/event/14.0.1.3/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/event/14.0.1.3/upgrade_analysis_work.txt index c097a62004b9..d6c392d1d0bd 100644 --- a/openupgrade_scripts/scripts/event/14.0.1.3/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/event/14.0.1.3/upgrade_analysis_work.txt @@ -13,7 +13,7 @@ event / event.event / date_tz (selection) : now a event / event.event / event_mail_ids (one2many) : now a function event / event.event / event_ticket_ids (one2many) : previously in module event_sale event / event.event / seats_max (integer) : now a function -# NOTHING TO DO +# NOTHING TO DO: Computed writable fields event / event.event / color (integer) : DEL # NOTHING TO DO: obsolete @@ -38,16 +38,16 @@ event / event.event / state (selection) : DEL re event / event.event / is_online (boolean) : DEL event / event.type / is_online (boolean) : DEL -# NOTHING TO DO: obsolete +# NOTHING TO DO: obsolete feature event / event.event / seats_min (integer) : DEL event / event.type / default_registration_min (integer): DEL -# NOTHING TO DO: obsolete +# NOTHING TO DO: obsolete feature event / event.event / twitter_hashtag (char) : DEL event / event.type / default_hashtag (char) : DEL event / event.type / use_hashtag (boolean) : DEL -# NOTHING TO DO: obsolete +# NOTHING TO DO: obsolete feature event / event.type / event_type_mail_ids (one2many): now a function event / event.type / event_type_ticket_ids (one2many): NEW relation: event.type.ticket, isfunction: function, stored @@ -75,7 +75,8 @@ event / event.event.ticket / seats_max (integer) : previo event / event.event.ticket / seats_reserved (integer) : previously in module event_sale event / event.event.ticket / seats_unconfirmed (integer) : previously in module event_sale event / event.event.ticket / seats_used (integer) : previously in module event_sale -# NOTHING TO DO +event / event.registration / event_ticket_id (many2one) : previously in module event_sale +# NOTHING TO DO: Handled by ORM when event_sale was installed event / event.event.ticket / end_sale_date (date) : NEW # DONE: pre-migration: renamed from deadline (of event_sale) @@ -88,14 +89,13 @@ event / event.event.ticket / start_sale_date (date) : NEW event / event.registration / _order : _order is now 'id desc' ('name, create_date desc') event / event.registration / date_closed (datetime) : now a function event / event.registration / email (char) : now a function -event / event.registration / event_ticket_id (many2one) : previously in module event_sale event / event.registration / mobile (char) : now a function event / event.registration / name (char) : now a function event / event.registration / phone (char) : now a function -# NOTHING TO DO +# NOTHING TO DO: Computed writable fields event / event.registration / origin (char) : DEL -# NOTHING TO DO: obsolete +# NOTHING TO DO: obsolete feature event / event.registration / utm_campaign_id (many2one) : NEW relation: utm.campaign event / event.registration / utm_medium_id (many2one) : NEW relation: utm.medium @@ -147,7 +147,6 @@ NEW ir.actions.act_window: event.event_tag_category_action_tree DEL ir.actions.act_window: event.action_event_confirm NEW ir.model.access: event.access_event_category NEW ir.model.access: event.access_event_category_manager -NEW ir.model.access: event.access_event_event_ticket_manager NEW ir.model.access: event.access_event_registration_all NEW ir.model.access: event.access_event_stage_manager NEW ir.model.access: event.access_event_stage_user @@ -159,8 +158,9 @@ DEL ir.model.access: event.access_event_registration_employee DEL ir.model.access: event.access_event_registration_portal # NOTHING TO DO +NEW ir.model.access: event.access_event_event_ticket_manager NEW ir.model.access: event.access_event_event_ticket_user [renamed from event_sale module] -# DONE: pre-migration: renamed xmlid (if event_sale installed) +# DONE: pre-migration: renamed xmlids from event_sale NEW ir.rule: event.ir_rule_event_event_ticket_company (noupdate) # NOTHING TO DO