[IMP] mass_mailing: hide mailing option on invalid

Currently when creating a composer in mass mode
the composer always shows the 'mass mailing name' option
even when a mailing cannot be created.

This silently creates a regular mass mail.

This hides that option when selecting records of models
that do not inherit from thread. So that users do not falsly
believe a mailing will be created.

task #2990447

closes odoo/odoo#102105

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Renaud Thiry
2022-10-06 14:56:49 +02:00
parent c90e18c3df
commit eaf905d55a
3 changed files with 15 additions and 7 deletions
@@ -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({
@@ -8,10 +8,11 @@
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='notify']" position="after">
<field name="model_is_thread" invisible="1"/>
<field name="campaign_id" groups="mass_mailing.group_mass_mailing_campaign"
attrs="{'invisible': [('composition_mode', '!=', 'mass_mail')]}"/>
attrs="{'invisible': ['|', ('composition_mode', '!=', 'mass_mail'), ('model_is_thread', '!=', True)]}"/>
<field name="mass_mailing_name"
attrs="{'invisible': [('composition_mode', '!=', 'mass_mail')]}"/>
attrs="{'invisible': ['|', ('composition_mode', '!=', 'mass_mail'), ('model_is_thread', '!=', True)]}"/>
</xpath>
<xpath expr="//button[@name='action_send_mail'][not(hasclass('o_mail_send'))]" position="attributes">
<!-- 'Log' button -->
+3 -3
View File
@@ -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',