Skip to content

Commit

Permalink
[FIX+IMP] event: Finish migration scripts
Browse files Browse the repository at this point in the history
* Refactor stages code
* Don't assign "Booked" stage, as it can't be determined by previous state
* Missing XML-ID renaming
  • Loading branch information
pedrobaeza committed Jul 19, 2021
1 parent 97cafff commit 7dd2bae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 58 deletions.
58 changes: 12 additions & 46 deletions openupgrade_scripts/scripts/event/14.0.1.3/post-migration.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,21 @@
# Copyright 2021 ForgeFlow S.L. <https://www.forgeflow.com>
# 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()
Expand Down
8 changes: 6 additions & 2 deletions openupgrade_scripts/scripts/event/14.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
]


Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7dd2bae

Please sign in to comment.