diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py
index db7f71cfd36..dd971aed708 100644
--- a/addons/mass_mailing/wizard/mail_compose_message.py
+++ b/addons/mass_mailing/wizard/mail_compose_message.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from odoo import fields, models
+from odoo import api, fields, models
class MailComposeMessage(models.TransientModel):
@@ -11,6 +11,13 @@ class MailComposeMessage(models.TransientModel):
campaign_id = fields.Many2one('utm.campaign', string='Mass Mailing Campaign', ondelete='set null')
mass_mailing_name = fields.Char(string='Mass Mailing Name', help='If set, a mass mailing will be created so that you can track its results in the Email Marketing app.')
mailing_list_ids = fields.Many2many('mailing.list', string='Mailing List')
+ model_is_thread = fields.Boolean(compute='_compute_model_is_thread')
+
+ @api.depends('model')
+ def _compute_model_is_thread(self):
+ for composer in self:
+ model = self.env['ir.model']._get(composer.model)
+ composer.model_is_thread = model.is_mail_thread
def get_mail_values(self, res_ids):
""" Override method that generated the mail content by creating the
@@ -22,7 +29,7 @@ class MailComposeMessage(models.TransientModel):
# use only for allowed models in mass mailing
if self.composition_mode == 'mass_mail' and \
(self.mass_mailing_name or self.mass_mailing_id) and \
- self.env['ir.model'].sudo().search_count([('model', '=', self.model), ('is_mail_thread', '=', True)]):
+ self.model_is_thread:
mass_mailing = self.mass_mailing_id
if not mass_mailing:
mass_mailing = self.env['mailing.mailing'].create({
diff --git a/addons/mass_mailing/wizard/mail_compose_message_views.xml b/addons/mass_mailing/wizard/mail_compose_message_views.xml
index ffc9bbe06e2..9b8bcf95be5 100644
--- a/addons/mass_mailing/wizard/mail_compose_message_views.xml
+++ b/addons/mass_mailing/wizard/mail_compose_message_views.xml
@@ -8,10 +8,11 @@
+
+ attrs="{'invisible': ['|', ('composition_mode', '!=', 'mass_mail'), ('model_is_thread', '!=', True)]}"/>
+ attrs="{'invisible': ['|', ('composition_mode', '!=', 'mass_mail'), ('model_is_thread', '!=', True)]}"/>
diff --git a/addons/test_mail/tests/test_performance.py b/addons/test_mail/tests/test_performance.py
index 2d3d8ef92bc..a66b9b7ad11 100644
--- a/addons/test_mail/tests/test_performance.py
+++ b/addons/test_mail/tests/test_performance.py
@@ -373,7 +373,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
test_record, _test_template = self._create_test_records()
customer = self.env['res.partner'].browse(self.customer.ids)
attachments = self.env['ir.attachment'].with_user(self.env.user).create(self.test_attachments_vals)
- with self.assertQueryCount(__system__=12, employee=12):
+ with self.assertQueryCount(__system__=13, employee=13):
composer_form = Form(
self.env['mail.compose.message'].with_context({
'default_composition_mode': 'comment',
@@ -497,7 +497,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
test_template.write({'attachment_ids': [(5, 0)]})
customer = self.env['res.partner'].browse(self.customer.ids)
- with self.assertQueryCount(__system__=34, employee=36): # tm 24/26 / com 33/35
+ with self.assertQueryCount(__system__=35, employee=37): # tm 24/26 / com 33/35
composer_form = Form(
self.env['mail.compose.message'].with_context({
'default_composition_mode': 'comment',
@@ -527,7 +527,7 @@ class TestMailAPIPerformance(BaseMailPerformance):
test_record, test_template = self._create_test_records()
customer = self.env['res.partner'].browse(self.customer.ids)
- with self.assertQueryCount(__system__=35, employee=37): # tm 25/27 / com 34/36
+ with self.assertQueryCount(__system__=36, employee=38): # tm 25/27 / com 34/36
composer_form = Form(
self.env['mail.compose.message'].with_context({
'default_composition_mode': 'comment',