Skip to content

Commit

Permalink
[MIG] mail: continue migration
Browse files Browse the repository at this point in the history
-This commit continuing migrate mail module, check analys file for more
info
  • Loading branch information
duong77476-viindoo authored and royle-vietnam committed Jun 1, 2024
1 parent 3d24dca commit 4480fba
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docsource/modules160-170.rst
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ Module coverage 16.0 -> 17.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| lunch | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| mail |Done (partial) | |
| mail |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| mail_bot |Nothing to do |No DB layout changes. |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
47 changes: 44 additions & 3 deletions openupgrade_scripts/scripts/mail/17.0.1.15/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,55 @@ def _fill_res_company_alias_domain_id(env):
if domain:
alias_domain = env["mail.alias.domain"].create(
{
"bounce_alias": icp.get_param("mail.bounce.alias"),
"catchall_alias": icp.get_param("mail.catchall.alias"),
"default_from": icp.get_param("mail.default.from"),
"bounce_alias": icp.get_param("mail.bounce.alias") or "bounce",
"catchall_alias": icp.get_param("mail.catchall.alias") or "catchall",
"default_from": icp.get_param("mail.default.from") or "notifications",
"name": domain,
}
)
companies = env["res.company"].with_context(active_test=False).search([])
companies.write({"alias_domain_id": alias_domain.id})


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
""",
)


def _mail_template_convert_report_template_m2o_to_m2m(env):
openupgrade.m2o_to_x2m(
env.cr,
env["mail.template"],
"mail_template",
"report_template_ids",
"report_template",
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env, "mail", "17.0.1.15/noupdate_changes.xml")
Expand All @@ -38,3 +77,5 @@ def migrate(env, version):
_deleted_xml_records,
)
_fill_res_company_alias_domain_id(env)
_mail_alias_fill_alias_full_name(env)
_mail_template_convert_report_template_m2o_to_m2m(env)
100 changes: 99 additions & 1 deletion openupgrade_scripts/scripts/mail/17.0.1.15/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,111 @@
("mail_channel_member", "discuss_channel_member"),
("mail_channel_rtc_session", "discuss_channel_rtc_session"),
]
_fields_renames = [
(
"discuss.channel",
"discuss_channel",
"field",
"field_id",
),
]


def _discuss_channel_fill_allow_public_upload(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE discuss_channel
ADD COLUMN IF NOT EXISTS allow_public_upload BOOLEAN;
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE discuss_channel
SET allow_public_upload = True
WHERE channel_type = 'livechat'
""",
)


def _mail_alias_fill_multiple_values(env):
"""
We will fill value for alias_full_name in post because alias_domain has not been
present yet
"""
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE mail_alias
ADD COLUMN IF NOT EXISTS alias_full_name VARCHAR,
ADD COLUMN IF NOT EXISTS alias_incoming_local BOOLEAN,
ADD COLUMN IF NOT EXISTS alias_status VARCHAR;
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE mail_alias
SET alias_incoming_local = True
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE mail_alias
SET alias_status = 'not_tested'
""",
)


def _mail_tracking_value_update_monetary_tracking_values(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE mail_tracking_value
SET old_value_float = old_value_monetary,
new_value_float = new_value_monetary
WHERE old_value_monetary IS NOT NULL
OR new_value_monetary IS NOT NULL;
""",
)


def _company_update_email_colors(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE res_company
ADD COLUMN IF NOT EXISTS email_primary_color VARCHAR,
ADD COLUMN IF NOT EXISTS email_secondary_color VARCHAR;
""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE res_company
SET email_primary_color = CASE
WHEN primary_color IS NOT NULL then primary_color
ELSE '#000000'
END,
email_secondary_color = CASE
WHEN secondary_color IS NOT NULL then secondary_color
ELSE '#875A7B'
END
""",
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_models(env.cr, _models_renames)
openupgrade.rename_tables(env.cr, _tables_renames)

openupgrade.rename_fields(env, _fields_renames)
_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)
# create column to avoid model mail.alias is loaded before model res.company
openupgrade.logged_query(
env.cr,
Expand Down
Loading

0 comments on commit 4480fba

Please sign in to comment.