[FIX] mail: raise a missing email error instead of crash when logging without email

Currently when posting a message if the author has no email address an user
error is raised. Indeed as posting a message goes through the process of
creating notifications and sending emails an email address is required on
the user.

In saas 11.2 a _message_log shortcut has been added to log notes. This
method should have the same behavior when author has no email. Currently
there is a crash when trying to encode its email. After this commit an
exceptions is raised like classic post.

This commit is related to task ID 1823990 .
This commit is contained in:
Thibault Delavallée
2018-04-10 14:45:33 +02:00
parent b7f43f265d
commit 2d19c4c6b8
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ class Message(models.Model):
def _get_default_from(self):
if self.env.user.email:
return formataddr((self.env.user.name, self.env.user.email))
raise UserError(_("Unable to send email, please configure the sender's email address."))
raise UserError(_("Unable to post message, please configure the sender's email address."))
@api.model
def _get_default_author(self):
+3 -3
View File
@@ -1998,16 +1998,16 @@ class MailThread(models.AbstractModel):
kw_author = kwargs.pop('author_id', False)
if kw_author:
author = self.env['res.partner'].sudo().browse(kw_author)
email_from = formataddr((author.name, author.email))
else:
author = self.env.user.partner_id
email_from = formataddr((author.name, author.email))
if not author.email:
raise exceptions.UserError(_("Unable to log message, please configure the sender's email address."))
message_values = {
'subject': subject,
'body': body,
'author_id': author.id,
'email_from': email_from,
'email_from': formataddr((author.name, author.email)),
'message_type': message_type,
'model': kwargs.get('model', self._name),
'res_id': self.ids[0] if self.ids else False,