Skip to content

Commit

Permalink
Merge pull request #3832 from acsone/16.0-mail-mle
Browse files Browse the repository at this point in the history
[16.0] [OU-ADD] mail
  • Loading branch information
pedrobaeza authored Jun 8, 2023
2 parents 94ad4d0 + 43c7b32 commit 37494be
Show file tree
Hide file tree
Showing 7 changed files with 381 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
19 changes: 19 additions & 0 deletions openupgrade_scripts/scripts/mail/16.0.1.10/noupdate_changes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<?xml version='1.0' encoding='utf-8'?>
<odoo>
<record id="ir_rule_mail_channel_member_group_system" model="ir.rule">
<field name="model_id" ref="model_mail_channel_member"/>
<field name="name">mail.channel.member: admin can manipulate all entries</field>
</record>
<record id="ir_rule_mail_channel_member_group_user" model="ir.rule">
<field name="domain_force">[
'|',
'&amp;',
('channel_id.channel_type', '!=', 'channel'),
('channel_id.is_member', '=', True),
'&amp;',
('channel_id.channel_type', '=', 'channel'),
'|',
('channel_id.group_public_id', '=', False),
('channel_id.group_public_id', 'in', [g.id for g in user.groups_id])]
</field>
<field name="model_id" ref="model_mail_channel_member"/>
<field name="name">mail.channel.member: write its own entries</field>
</record>
<record id="mail_channel_rule" model="ir.rule">
<field name="domain_force">[
'|',
Expand Down
9 changes: 9 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,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 openupgrade_scripts/scripts/mail/16.0.1.10/pre-migration.py
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)
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 37494be

Please sign in to comment.