Skip to content

Commit

Permalink
[OU-ADD] mail
Browse files Browse the repository at this point in the history
  • Loading branch information
marielejeune committed Jun 7, 2023
1 parent 2036c97 commit eb2442f
Show file tree
Hide file tree
Showing 6 changed files with 363 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docsource/modules150-160.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ Module coverage 15.0 -> 16.0
+-------------------------------------------------+----------------------+-------------------------------------------------+
| lunch | | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| mail | | |
| mail | Done | |
+-------------------------------------------------+----------------------+-------------------------------------------------+
| mail_bot | |No DB layout changes. |
+-------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
16 changes: 16 additions & 0 deletions openupgrade_scripts/scripts/mail/16.0.1.10/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env.cr, "mail", "16.0.1.10/noupdate_changes.xml")
openupgrade.delete_records_safely_by_xml_id(
env,
[
"mail.ir_rule_mail_channel_partner_group_user",
"mail.ir_rule_mail_channel_partner_group_system",
],
)
92 changes: 92 additions & 0 deletions openupgrade_scripts/scripts/mail/16.0.1.10/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade

_fields_renames = [
(
"mail.channel",
"mail_channel",
"channel_last_seen_partner_ids",
"channel_member_ids",
)
]
_models_renames = [("mail.channel.partner", "mail.channel.member")]
_tables_renames = [("mail_channel_partner", "mail_channel_member")]
_columns_renames = {
"mail_message": [("add_sign", "email_add_signature")],
}
_xmlids_renames = [
(
"channel_partner_general_channel_for_admin",
"channel_member_general_channel_for_admin",
)
]
_columns_copies = {
"mail_channel_rtc_session": [
("channel_partner_id", "channel_member_id", "integer")
],
}


def ir_act_server_rename_state_email(env):
"""
ir.actions.server state selection key 'email' is now 'mail_post'.
"""
openupgrade.logged_query(
env.cr,
"""
UPDATE ir_act_server
SET state='mail_post'
WHERE state='email';
""",
)


def mail_channel_channel_type_required(env):
"""
channel_type is now required on mail.channel.
Set default value 'channel' if no value was set.
"""
openupgrade.logged_query(
env.cr,
"""
UPDATE mail_channel
SET channel_type='channel'
WHERE channel_type IS NULL;
""",
)


def scheduled_date_set_empty_strings_to_null(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE mail_mail
SET scheduled_date = NULL
WHERE scheduled_date = '';
""",
)


def delete_obsolete_constraints(env):
openupgrade.delete_sql_constraint_safely(
env, "mail", "mail_channel_partner", "partner_or_guest_exists"
)
openupgrade.delete_sql_constraint_safely(
env, "mail", "mail_channel_rtc_session", "channel_partner_unique"
)


@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_fields(env, _fields_renames)
openupgrade.rename_models(env.cr, _models_renames)
openupgrade.rename_tables(env.cr, _tables_renames)
openupgrade.rename_columns(env.cr, _columns_renames)
openupgrade.copy_columns(env.cr, _columns_copies)
openupgrade.rename_xmlids(env.cr, _xmlids_renames)
ir_act_server_rename_state_email(env)
mail_channel_channel_type_required(env)
scheduled_date_set_empty_strings_to_null(env)
delete_obsolete_constraints(env)
8 changes: 8 additions & 0 deletions openupgrade_scripts/scripts/mail/16.0.1.10/tests/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
env = locals().get("env")
# create a mail with a scheduled date as char to be sure it was correctly
# migrated as datetime field in v16.
env["mail.mail"].create(
{"body_html": "TEST date", "scheduled_date": "2023-04-12 10:05:01"}
)
env["mail.mail"].create({"body_html": "TEST empty date", "scheduled_date": ""})
env.cr.commit()
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import datetime

from odoo.tests import TransactionCase


class TestMailMigration(TransactionCase):
def test_mail_scheduled_date(self):
"""Make sure that the scheduled date was preserved as changing
the field type from char to datetime.
"""
mail_with_date = self.env["mail.mail"].search(
[("body_html", "=", "TEST date")], limit=1
)
self.assertEqual(len(mail_with_date), 1)
self.assertEqual(
mail_with_date.scheduled_date,
datetime(2023, 4, 12, 10, 5, 1),
)
mail_without_date = self.env["mail.mail"].search(
[("body_html", "=", "TEST empty date")], limit=1
)
self.assertEqual(len(mail_without_date), 1)
self.assertFalse(mail_without_date.scheduled_date)
Loading

0 comments on commit eb2442f

Please sign in to comment.