[FIX] mail: fix model typo in message_notify

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) <xdo@odoo.com>
This commit is contained in:
Hardik Prajapati
2019-08-05 13:24:48 +00:00
committed by Xavier-Do
parent dfe9f1749b
commit f24d23299b
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -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
+4 -1
View File
@@ -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)