-
-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2036c97
commit 19043f8
Showing
4 changed files
with
389 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
45 changes: 45 additions & 0 deletions
45
openupgrade_scripts/scripts/mail/16.0.1.10/post-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,45 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
def _mail_mail_convert_scheduled_datetime_from_str_to_date(env): | ||
""" | ||
On mail.mail scheduled_date was a string, it is now a datetime. | ||
Old column scheduled_date was renamed using get_legacy_name | ||
in pre-migration script. | ||
This field contained a char representing a datetime, possibly with a | ||
timezone. Make use of _parse_scheduled_datetime method from mail.mail | ||
to keep consistency (this is the method used in Odoo code when dealing | ||
with this field). | ||
""" | ||
old_scheduled_date_name = openupgrade.get_legacy_name("scheduled_date") | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
SELECT id, %(old_col_name)s | ||
FROM mail_mail | ||
WHERE %(old_col_name)s IS NOT NULL | ||
""" | ||
% {"old_col_name": old_scheduled_date_name}, | ||
) | ||
for res in env.cr.fetchall(): | ||
scheduled_date = res[1] | ||
parsed_datetime = env["mail.mail"]._parse_scheduled_datetime(scheduled_date) | ||
parsed_datetime = ( | ||
parsed_datetime.replace(tzinfo=None) if parsed_datetime else False | ||
) | ||
env["mail.mail"].browse(res[0]).scheduled_date = parsed_datetime | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_mail_mail_convert_scheduled_datetime_from_str_to_date(env) | ||
openupgrade.delete_records_safely_by_xml_id( | ||
env, | ||
[ | ||
"mail.ir_rule_mail_channel_partner_group_user", | ||
"mail.ir_rule_mail_channel_partner_group_system", | ||
], | ||
) |
120 changes: 120 additions & 0 deletions
120
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,120 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openupgradelib import openupgrade | ||
|
||
_models_renames = [("mail.channel.partner", "mail.channel.member")] | ||
_tables_renames = [("mail_channel_partner", "mail_channel_member")] | ||
_columns_renames = { | ||
"mail_mail": [("scheduled_date", None)], | ||
"mail_message": [("add_sign", "email_add_signature")], | ||
} | ||
_columns_copies = { | ||
"mail_channel_rtc_session": [ | ||
("channel_partner_id", "channel_member_id", "integer") | ||
], | ||
} | ||
|
||
|
||
def mail_channel_member_ir_model_data(env): | ||
""" | ||
Update ir.model.data name that changed. Otherwise Odoo tries to load | ||
this data a second time, but it fails because of a unicity constraint | ||
""" | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE ir_model_data | ||
SET name='channel_member_general_channel_for_admin' | ||
WHERE name='channel_partner_general_channel_for_admin' | ||
""", | ||
) | ||
|
||
|
||
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 ir_act_server_compute_mail_post_method(env): | ||
""" | ||
Add mail_post_method column on ir_act_server and compute the values | ||
""" | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
ALTER TABLE ir_act_server | ||
ADD mail_post_method varchar; | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE ir_act_server | ||
SET mail_post_method='email' | ||
WHERE state = 'mail_post'; | ||
""", | ||
) | ||
|
||
|
||
def ir_act_server_compute_mail_post_autofollow(env): | ||
""" | ||
Add mail_post_autofollow column on ir_act_server and compute the values. | ||
The compute method also sets mail_post_autofollow = True for records having | ||
state='mail_post' and mail_post_method != 'email', but this case | ||
cannot happen right now, as mail_post_method is a new column | ||
populated right before with 'mail_post_method = 'email' on all records | ||
having state='mail_post'. | ||
""" | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
ALTER TABLE ir_act_server | ||
ADD mail_post_autofollow boolean; | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE ir_act_server | ||
SET mail_post_autofollow='f' | ||
WHERE state != 'mail_post' OR mail_post_method='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; | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
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) | ||
mail_channel_member_ir_model_data(env) | ||
ir_act_server_rename_state_email(env) | ||
ir_act_server_compute_mail_post_method(env) | ||
ir_act_server_compute_mail_post_autofollow(env) | ||
mail_channel_channel_type_required(env) |
Oops, something went wrong.