From f24d23299b64d6643d05a2d1e8b48edb0f4916cb Mon Sep 17 00:00:00 2001 From: Hardik Prajapati Date: Thu, 1 Aug 2019 13:37:38 +0000 Subject: [PATCH] [FIX] mail: fix model typo in message_notify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since #32404, the fallback case where we have no recipients and no parent_id on message notify has a typo on mail_message. A user will receive a traceback when using compose message wizard on a record not inheriting from mail_thread if he forgot to add recipients. If the typo should be fixed, notifying the user that no recipients were found and thus, message_notify won't do anything could be interresting. We can raise a UserError to give a more explicit failure reason. We would like to avoid to raise this error on a low level like in message_notify to avoid to break mail_gateway mechanism, but raising it from mail.compose.message send_mail shouldn't have any side effect. We can simply check the output of message_notify to know if something was done to avoid to duplicate logic used to define recipients. task-2046180 closes odoo/odoo#35378 Signed-off-by: Xavier Dollé (xdo) --- addons/mail/models/mail_thread.py | 2 +- addons/mail/wizard/mail_compose_message.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 662edbeac5d..77018787e82 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1893,7 +1893,7 @@ class MailThread(models.AbstractModel): if not partner_ids: _logger.warning('Message notify called without recipient_ids, skipping') - return self.env['mail_message'] + return self.env['mail.message'] if not (model and res_id): # both value should be set or none should be set (record) model = False diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index cd0da38fbb0..a968bb80cd9 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -8,6 +8,7 @@ import re from odoo import _, api, fields, models, SUPERUSER_ID, tools from odoo.tools.safe_eval import safe_eval +from odoo.exceptions import UserError # main mako-like expression pattern @@ -283,7 +284,9 @@ class MailComposer(models.TransientModel): if wizard.model: post_params['model'] = wizard.model post_params['res_id'] = res_id - ActiveModel.message_notify(**post_params) + if not ActiveModel.message_notify(**post_params): + # if message_notify returns an empty record set, no recipients where found. + raise UserError(_("No recipient found.")) else: ActiveModel.browse(res_id).message_post(**post_params)