-
-
Notifications
You must be signed in to change notification settings - Fork 829
[17.0][OU-ADD] mail: migration to 17.0 #4600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
openupgrade_scripts/scripts/mail/17.0.1.15/post-migration.py
This file contains hidden or 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,102 @@ | ||
| # Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| _deleted_xml_records = [ | ||
| "mail.ir_rule_mail_channel_member_group_system", | ||
| "mail.ir_rule_mail_channel_member_group_user", | ||
| "mail.mail_channel_admin", | ||
| "mail.mail_channel_rule", | ||
| "mail.channel_all_employees", | ||
| "mail.channel_member_general_channel_for_admin", | ||
| ] | ||
|
|
||
|
|
||
| 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: | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| f""" | ||
| INSERT INTO mail_alias_domain ( | ||
| name, bounce_alias, catchall_alias, default_from) | ||
| VALUES ( | ||
| '{domain}', | ||
| '{icp.get_param("mail.bounce.alias") or "bounce"}', | ||
| '{icp.get_param("mail.catchall.alias") or "catchall"}', | ||
| '{icp.get_param("mail.default.from") or "notifications"}' | ||
| ) | ||
| RETURNING id; | ||
| """, | ||
| ) | ||
| (alias_domain_id,) = env.cr.fetchone() | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| f""" | ||
| UPDATE res_company | ||
| SET alias_domain_id = {alias_domain_id} | ||
| WHERE alias_domain_id IS NULL; | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| f""" | ||
| UPDATE mail_alias | ||
| SET alias_domain_id = {alias_domain_id} | ||
| WHERE alias_domain_id IS NULL; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _mail_alias_fill_alias_full_name(env): | ||
| 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): | ||
| 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") | ||
| openupgrade.delete_records_safely_by_xml_id( | ||
| 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) | ||
127 changes: 127 additions & 0 deletions
127
openupgrade_scripts/scripts/mail/17.0.1.15/pre-migration.py
This file contains hidden or 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,127 @@ | ||
| # Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from openupgradelib import openupgrade | ||
|
|
||
| _models_renames = [ | ||
| ("mail.channel", "discuss.channel"), | ||
| ("mail.channel.member", "discuss.channel.member"), | ||
| ("mail.channel.rtc.session", "discuss.channel.rtc.session"), | ||
| ] | ||
| _tables_renames = [ | ||
| ("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 = [ | ||
| ( | ||
| "mail.tracking.value", | ||
| "mail_tracking_value", | ||
| "field", | ||
| "field_id", | ||
| ), | ||
| ] | ||
| _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): | ||
| """ | ||
| 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, | ||
| alias_status = 'valid' | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| 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 _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='admin@example.com' | ||
| WHERE email IS NULL | ||
| """ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @remi-filament I think we should fill this with a dummy value after all, otherwise Odoo won't be able to set up the not null constraint |
||
| ) | ||
|
|
||
|
|
||
| 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) | ||
| 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, | ||
| """ | ||
| ALTER TABLE res_company | ||
| ADD COLUMN IF NOT EXISTS alias_domain_id INTEGER; | ||
| """, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.