Skip to content

Commit

Permalink
[OU-IMP] review followups
Browse files Browse the repository at this point in the history
Co-Authored-By: Pedro M. Baeza <[email protected]>
  • Loading branch information
hbrunn and pedrobaeza committed Oct 25, 2024
1 parent a087736 commit d536986
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="domain_force">['|', ('create_uid', '=', user.id), ('user_id', '=', user.id)]</field>
<field name="name">Employees can only modify templates they have created or been assigned</field>
</record>
<record id="module_install_notification" model="mail.message">
<!-- <record id="module_install_notification" model="mail.message">
<field name="model">discuss.channel</field>
</record>
</record> -->
</odoo>
55 changes: 28 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 @@ -13,12 +13,23 @@
]


def _discuss_channel_fill_allow_public_upload(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE discuss_channel
SET allow_public_upload = True
WHERE channel_type = 'livechat'
""",
)


def _fill_res_company_alias_domain_id(env):
icp = env["ir.config_parameter"]

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 +43,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 +63,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 All @@ -96,6 +96,7 @@ def migrate(env, version):
env,
_deleted_xml_records,
)
_discuss_channel_fill_allow_public_upload(env)
_fill_res_company_alias_domain_id(env)
_mail_alias_fill_alias_full_name(env)
_mail_template_convert_report_template_m2o_to_m2m(env)
58 changes: 29 additions & 29 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,33 +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",
),
]


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'
""",
)
_columns_renames = {
"discuss_channel_res_groups_rel": [
("mail_channel_id", "discuss_channel_id"),
],
}
_columns_copies = {
"mail_template": [
("report_template", None, None),
],
}


def _mail_alias_fill_multiple_values(env):
Expand All @@ -58,14 +51,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 +71,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 +111,12 @@ 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)
openupgrade.rename_columns(env.cr, _columns_renames)
openupgrade.copy_columns(env.cr, _columns_copies)
_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
Loading

0 comments on commit d536986

Please sign in to comment.