Skip to content

Commit

Permalink
[OU-IMP] review followups
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Oct 21, 2024
1 parent 7dd7224 commit 315e01b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 42 deletions.
43 changes: 16 additions & 27 deletions openupgrade_scripts/scripts/mail/17.0.1.15/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _fill_res_company_alias_domain_id(env):

domain = icp.get_param("mail.catchall.domain")
if domain:
alias_domain_id = openupgrade.logged_query(
openupgrade.logged_query(
env.cr,
f"""
INSERT INTO mail_alias_domain (
Expand All @@ -32,6 +32,7 @@ def _fill_res_company_alias_domain_id(env):
RETURNING id;
""",
)
(alias_domain_id,) = env.cr.fetchone()
openupgrade.logged_query(
env.cr,
f"""
Expand All @@ -51,32 +52,20 @@ def _fill_res_company_alias_domain_id(env):


def _mail_alias_fill_alias_full_name(env):
# Because we fill same alias domain for every company so only need one here
company = env["res.company"].search([], limit=1)
if company.alias_domain_id:
openupgrade.logged_query(
env.cr,
f"""
UPDATE mail_alias
SET alias_domain_id = {company.alias_domain_id.id},
alias_full_name = CASE
WHEN alias_name IS NOT NULL
THEN alias_name || '@' || '{company.alias_domain_id.name}'
ELSE NULL
END
""",
)
else:
openupgrade.logged_query(
env.cr,
"""
UPDATE mail_alias
SET alias_full_name = CASE
WHEN alias_name IS NOT NULL THEN alias_name
ELSE NULL
END
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE mail_alias
SET
alias_domain_id = mail_alias_domain.id,
alias_full_name = CASE
WHEN alias_name IS NOT NULL
THEN alias_name || '@' || mail_alias_domain.name
ELSE NULL
END
FROM mail_alias_domain
""",
)


def _mail_template_convert_report_template_m2o_to_m2m(env):
Expand Down
39 changes: 29 additions & 10 deletions openupgrade_scripts/scripts/mail/17.0.1.15/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@
("mail_channel", "discuss_channel"),
("mail_channel_member", "discuss_channel_member"),
("mail_channel_rtc_session", "discuss_channel_rtc_session"),
("mail_channel_res_groups_rel", "discuss_channel_res_groups_rel"),
]
_fields_renames = [
(
"discuss.channel",
"discuss_channel",
"mail.tracking.value",
"mail_tracking_value",
"field",
"field_id",
),
]
_columns_renames = {
"discuss_channel_res_groups_rel": [
("mail_channel_id", "discuss_channel_id"),
],
}
_columns_copies = {
"mail_template": [
("report_template", None, None),
],
}


def _discuss_channel_fill_allow_public_upload(env):
Expand Down Expand Up @@ -58,14 +69,9 @@ def _mail_alias_fill_multiple_values(env):
env.cr,
"""
UPDATE mail_alias
SET alias_incoming_local = True
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE mail_alias
SET alias_status = 'not_tested'
SET
alias_incoming_local = True,
alias_status = 'valid'
""",
)

Expand All @@ -83,6 +89,16 @@ def _mail_tracking_value_update_monetary_tracking_values(env):
)


def _mail_gateway_allowed(env):
"""Set some dummy value so that the not null constraint can be created"""
env.cr.execute(
"""
UPDATE mail_gateway_allowed SET email='[email protected]'
WHERE email IS NULL"
"""
)


def _company_update_email_colors(env):
openupgrade.logged_query(
env.cr,
Expand Down Expand Up @@ -113,10 +129,13 @@ def migrate(env, version):
openupgrade.rename_models(env.cr, _models_renames)
openupgrade.rename_tables(env.cr, _tables_renames)
openupgrade.rename_fields(env, _fields_renames)
openupgrade.rename_columns(env.cr, _columns_renames)
openupgrade.copy_columns(env.cr, _columns_copies)
_discuss_channel_fill_allow_public_upload(env)
_mail_alias_fill_multiple_values(env)
_mail_tracking_value_update_monetary_tracking_values(env)
_company_update_email_colors(env)
_mail_gateway_allowed(env)
# create column to avoid model mail.alias is loaded before model res.company
openupgrade.logged_query(
env.cr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ mail / mail.template / report_name (char) : DEL

mail / mail.template / report_template (many2one) : DEL relation: ir.actions.report
mail / mail.template / report_template_ids (many2many): NEW relation: ir.actions.report
# DONE pre-migraton: m2o to m2m
# DONE post-migraton: m2o to m2m

mail / mail.template / user_id (many2one) : NEW relation: res.users
# NOTHING TO DO: new feature
Expand All @@ -265,7 +265,7 @@ mail / mail.tracking.value / field_id (many2one) : NEW re

mail / mail.tracking.value / new_value_monetary (float) : DEL
mail / mail.tracking.value / old_value_monetary (float) : DEL
# TODO pre-migration: fill value into old/new_value_float
# DONE pre-migration: fill value into old/new_value_float

mail / mail.alias.domain / bounce_alias (char) : NEW required, hasdefault: default
mail / mail.alias.domain / catchall_alias (char) : NEW required, hasdefault: default
Expand Down Expand Up @@ -298,7 +298,7 @@ mail / res.users / res_users_settings_ids (one2many): mod
mail / res.users.settings / _order : module is now 'base' ('mail')
mail / res.users.settings / display_name (char) : module is now 'base' ('mail')
mail / res.users.settings / user_id (many2one) : module is now 'base' ('mail')
# NOTHING TODO
# NOTHING TO DO: done in base migration scripts

---XML records in module 'mail'---
NEW discuss.channel: mail.channel_all_employees (noupdate)
Expand Down Expand Up @@ -408,7 +408,7 @@ DEL ir.rule: mail.ir_rule_mail_channel_member_group_system (noupdate)
DEL ir.rule: mail.ir_rule_mail_channel_member_group_user (noupdate)
DEL ir.rule: mail.mail_channel_admin (noupdate)
DEL ir.rule: mail.mail_channel_rule (noupdate)
# NOTHING TO DO: removed in post-migration
# DONE: post-migration: safe removal

DEL ir.rule: mail.res_users_settings_rule_admin [renamed to base module] (noupdate)
DEL ir.rule: mail.res_users_settings_rule_user [renamed to base module] (noupdate)
Expand Down Expand Up @@ -482,7 +482,7 @@ DEL ir.ui.view: mail.view_mail_alias_tree

DEL mail.channel: mail.channel_all_employees (noupdate)
DEL mail.channel.member: mail.channel_member_general_channel_for_admin (noupdate)
# NOTHING TO DO: removed in post-migration
# DONE: post-migration: safe removal

NEW res.groups: mail.group_mail_notification_type_inbox (noupdate)
# NOTHING TO DO

0 comments on commit 315e01b

Please sign in to comment.