From 6230f72d2be58069dfd264623944a45c84c99ba4 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 24 Jun 2019 14:03:46 +0000 Subject: [PATCH] [FIX] mail: avoid crashing for users without email address --- addons/mail/models/mail_thread.py | 6 +++++- addons/mail/wizard/mail_compose_message.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index ac5bb415ee0..a7245bb476f 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1929,9 +1929,13 @@ class MailThread(models.AbstractModel): self.ensure_one() if author_id: author = self.env['res.partner'].sudo().browse(author_id) - else: + elif self.env.user.email: author = self.env.user.partner_id author_id = author.id + else: + # the current user has no email address (like the public user) + author = self.env.user.browse(SUPERUSER_ID).partner_id + author_id = author.id if not author.email: raise exceptions.UserError(_("Unable to log message, please configure the sender's email address.")) diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 18deb40800b..f5ad45c0a56 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -63,7 +63,7 @@ class MailComposer(models.TransientModel): if 'author_id' not in result: result['author_id'] = self.env.user.partner_id.id if 'email_from' not in result: - result['email_from'] = formataddr((self.env.user.name, self.env.user.email)) + result['email_from'] = formataddr((self.env.user.name, self.env.user.email or "")) else: if 'email_from' not in result: author = self.env['res.partner'].browse(result['author_id'])