Skip to content
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

[15.0][MIG] event #3500

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules140-150.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Module coverage 14.0 -> 15.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| digest |Nothing to do |No DB layout changes. |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| event | | |
| event | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| |new| event_booth | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
94 changes: 94 additions & 0 deletions openupgrade_scripts/scripts/event/15.0.1.6/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2022 ForgeFlow
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


def date_to_datetime_tz(env, date_field_name, datetime_field_name):
# based in openupgrade.date_to_datetime_tz
env.cr.execute(
"""
SELECT distinct(ee.date_tz)
FROM event_event_ticket eet
JOIN event_event ee ON eet.event_id = ee.id
WHERE ee.date_tz IS NOT NULL
"""
)
for (timezone,) in env.cr.fetchall():
env.cr.execute("SET TIMEZONE=%s", (timezone,))
values = {
"date_field_name": date_field_name,
"datetime_field_name": datetime_field_name,
"timezone": timezone,
}
openupgrade.logged_query(
env.cr,
"""
UPDATE event_event_ticket eet
SET %(datetime_field_name)s =
eet.%(date_field_name)s::TIMESTAMP AT TIME ZONE 'UTC'
FROM event_event ee
WHERE eet.%(date_field_name)s IS NOT NULL
AND eet.event_id = ee.id
AND ee.date_tz='%(timezone)s';
"""
% values,
)
env.cr.execute("RESET TIMEZONE")


def fill_event_event_ticket_datetime_fields(env):
date_to_datetime_tz(
env, openupgrade.get_legacy_name("start_sale_date"), "start_sale_datetime"
)
date_to_datetime_tz(
env, openupgrade.get_legacy_name("end_sale_date"), "end_sale_datetime"
)


def fill_event_type_note(env):
# only if all events linked to that event type have the same note
openupgrade.logged_query(
env.cr,
"""
WITH sub AS (
SELECT ee.event_type_id, ee.note
FROM event_event ee
WHERE ee.event_type_id IS NOT NULL
GROUP BY ee.event_type_id, ee.note
), sub2 AS (
SELECT event_type_id, count(*) AS count_notes
FROM sub
GROUP BY event_type_id
)
UPDATE event_type et
SET note = sub.note
FROM sub
JOIN sub2 ON (sub.event_type_id = sub2.event_type_id
AND sub2.count_notes = 1)
WHERE sub.event_type_id = et.id AND sub.note IS NOT NULL
""",
)


@openupgrade.migrate()
def migrate(env, version):
fill_event_event_ticket_datetime_fields(env)
fill_event_type_note(env)
openupgrade.load_data(env.cr, "event", "15.0.1.6/noupdate_changes.xml")
openupgrade.delete_record_translations(
env.cr,
"event",
[
"event_registration_mail_template_badge",
"event_reminder",
"event_subscription",
],
)
openupgrade.logged_query(
env.cr,
"""
DELETE FROM ir_model_data
WHERE module = 'event' AND name = 'paperformat_euro_lowmargin'
""",
)
96 changes: 96 additions & 0 deletions openupgrade_scripts/scripts/event/15.0.1.6/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2022 ForgeFlow
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

_column_renames = {
"event_event_ticket": [
("start_sale_date", None),
("end_sale_date", None),
],
}

_field_renames = [("event.mail", "event_mail", "done", "mail_done")]


def fill_event_registration_active(env):
if openupgrade.column_exists(env.cr, "event_registration", "active"):
return
openupgrade.add_fields(
env,
[
(
"active",
"event.registration",
"event_registration",
"boolean",
"bool",
"event",
True,
)
],
)


def fill_event_mail_mail_count_done(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE event_mail
ADD COLUMN IF NOT EXISTS mail_count_done integer;""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE event_mail em
SET mail_count_done = count_emr
FROM (SELECT em.id, count(emr.id) as count_emr
FROM event_mail em
JOIN event_mail_registration emr ON emr.scheduler_id = em.id
WHERE emr.mail_sent AND em.interval_type = 'after_sub'
GROUP BY em.id) sub
WHERE sub.id = em.id;""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE event_mail em
SET mail_count_done = ee.seats_reserved + ee.seats_used
FROM event_event ee
WHERE em.interval_type != 'after_sub'
AND em.notification_type = 'mail' AND em.template_id IS NOT NULL
AND em.event_id = ee.id;""",
)


def fill_event_mail_template_ref(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE event_mail
ADD COLUMN IF NOT EXISTS template_ref VARCHAR;
UPDATE event_mail
SET template_ref = 'mail.template,' || template_id
WHERE template_id IS NOT NULL AND notification_type = 'mail'
""",
)
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE event_type_mail
ADD COLUMN IF NOT EXISTS template_ref VARCHAR;
UPDATE event_type_mail
SET template_ref = 'mail.template,' || template_id
WHERE template_id IS NOT NULL AND notification_type = 'mail'
""",
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_columns(env.cr, _column_renames)
openupgrade.rename_fields(env, _field_renames)
openupgrade.convert_field_to_html(env.cr, "event_event", "note", "note")
fill_event_registration_active(env)
fill_event_mail_mail_count_done(env)
fill_event_mail_template_ref(env)
103 changes: 103 additions & 0 deletions openupgrade_scripts/scripts/event/15.0.1.6/upgrade_analysis_work.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---Models in module 'event'---
---Fields in module 'event'---
event / event.event / badge_back (html) : DEL
event / event.event / badge_front (html) : DEL
event / event.event / badge_innerleft (html) : DEL
event / event.event / badge_innerright (html) : DEL
event / event.event / event_logo (html) : DEL
# NOTHING TO DO: they were fields inaccessible through views

event / event.event / note (text) : now a function
event / event.event / note (text) : type is now 'html' ('text')
event / event.type / note (html) : NEW
# DONE: pre-migration: changed type
# DONE: post-migration: moved content to event type note

event / event.event / ticket_instructions (html) : NEW isfunction: function, stored
event / event.type / ticket_instructions (html) : NEW
# NOTHING TO DO: new feature

event / event.event.ticket / end_sale_date (date) : DEL
event / event.event.ticket / end_sale_datetime (datetime) : NEW
event / event.event.ticket / start_sale_date (date) : DEL
event / event.event.ticket / start_sale_datetime (datetime): NEW
# DONE: post-migration: filled new fields using old ones

event / event.mail / done (boolean) : DEL
event / event.mail / mail_done (boolean) : NEW
event / event.mail / mail_sent (boolean) : DEL
# DONE: pre-migration: renamed field 'done' to 'mail_done'

event / event.mail / mail_count_done (integer) : NEW
# DONE: pre-migration: computed mail_count_done

event / event.mail / template_id (many2one) : DEL relation: mail.template
event / event.mail / template_ref (reference) : NEW required
event / event.type.mail / template_id (many2one) : DEL relation: mail.template
event / event.type.mail / template_ref (reference) : NEW required
# DONE: pre-migration: transformed m2o to reference

event / event.registration / active (boolean) : NEW hasdefault
# DONE: pre-migration: set active = TRUE

event / event.type / event_type_mail_ids (one2many): not a function anymore
event / event.type / event_type_ticket_ids (one2many): not a function anymore
event / event.type / use_mail_schedule (boolean) : DEL
event / event.type / use_ticket (boolean) : DEL
event / event.type / use_timezone (boolean) : DEL
# NOTHING TO DO

---XML records in module 'event'---
NEW ir.actions.report: event.action_report_event_event_foldable_badge
NEW ir.actions.report: event.action_report_event_event_full_page_ticket
NEW ir.actions.report: event.action_report_event_registration_foldable_badge
NEW ir.actions.report: event.action_report_event_registration_full_page_ticket
DEL ir.actions.report: event.report_event_event_badge
DEL ir.actions.report: event.report_event_registration_badge
NEW ir.model.access: event.access_event_event_registration
NEW ir.model.access: event.access_event_event_ticket
NEW ir.model.access: event.access_event_event_ticket_registration
NEW ir.model.access: event.access_event_mail_registration_registration
NEW ir.model.access: event.access_event_mail_user
NEW ir.model.access: event.access_event_registration_manager
NEW ir.model.access: event.access_event_registration_registration
NEW ir.model.access: event.access_event_stage_registration
NEW ir.model.access: event.access_event_tag_category_registration
NEW ir.model.access: event.access_event_tag_category_user
NEW ir.model.access: event.access_event_tag_registration
NEW ir.model.access: event.access_event_tag_user
NEW ir.model.access: event.access_event_type_mail_manager
NEW ir.model.access: event.access_event_type_mail_registration
NEW ir.model.access: event.access_event_type_registration
NEW ir.model.access: event.access_event_type_ticket_registration
DEL ir.model.access: event.access_event_category
DEL ir.model.access: event.access_event_category_manager
DEL ir.model.access: event.access_event_event_portal
DEL ir.model.access: event.access_event_event_ticket_manager
DEL ir.model.access: event.access_event_mail
DEL ir.model.access: event.access_event_mail_manager
DEL ir.model.access: event.access_event_registration_all
DEL ir.model.access: event.access_event_stage_user
DEL ir.model.access: event.access_event_type [renamed to website_event module]
DEL ir.model.access: event.access_event_type_mail_event_manager
DEL ir.model.access: event.access_event_type_mail_event_user
DEL ir.model.access: event.access_event_type_ticket
NEW ir.ui.view: event.event_event_report_template_foldable_badge
NEW ir.ui.view: event.event_event_report_template_full_page_ticket
NEW ir.ui.view: event.event_registration_report_template_foldable_badge
NEW ir.ui.view: event.event_registration_report_template_full_page_ticket
NEW ir.ui.view: event.event_report_full_page_ticket_layout
NEW ir.ui.view: event.event_report_template_foldable_badge
NEW ir.ui.view: event.event_report_template_formatted_event_address
NEW ir.ui.view: event.event_report_template_full_page_ticket
DEL ir.ui.view: event.assets_backend
DEL ir.ui.view: event.assets_common
DEL ir.ui.view: event.event_event_report_template_badge
DEL ir.ui.view: event.event_registration_report_template_badge
NEW report.paperformat: event.paperformat_event_foldable_badge
NEW report.paperformat: event.paperformat_event_full_page_ticket
NEW res.groups: event.group_event_registration_desk
# NOTHING TO DO

DEL report.paperformat: event.paperformat_euro_lowmargin
# DONE: post-migration: deleted ir.model.data to avoid the record getting deleted