-
-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3832 from acsone/16.0-mail-mle
[16.0] [OU-ADD] mail
- Loading branch information
Showing
7 changed files
with
381 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
openupgrade_scripts/scripts/mail/16.0.1.10/noupdate_changes.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 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") |
100 changes: 100 additions & 0 deletions
100
openupgrade_scripts/scripts/mail/16.0.1.10/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# 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 = [ | ||
( | ||
"mail.channel_partner_general_channel_for_admin", | ||
"mail.channel_member_general_channel_for_admin", | ||
), | ||
( | ||
"mail.ir_rule_mail_channel_partner_group_system", | ||
"mail.ir_rule_mail_channel_member_group_system", | ||
), | ||
( | ||
"mail.ir_rule_mail_channel_partner_group_user", | ||
"mail.ir_rule_mail_channel_member_group_user", | ||
), | ||
] | ||
_columns_copies = { | ||
"mail_channel_rtc_session": [ | ||
("channel_partner_id", "channel_member_id", "integer") | ||
], | ||
} | ||
|
||
|
||
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" | ||
) | ||
|
||
|
||
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 = ''; | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
delete_obsolete_constraints(env) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
23 changes: 23 additions & 0 deletions
23
openupgrade_scripts/scripts/mail/16.0.1.10/tests/test_mail_migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.