From d8deacfdc3d15ce1d1dd23640d57404ad02ad6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 10 Jul 2019 14:50:07 +0000 Subject: [PATCH] [FIX] mail: set email_from in composer only if set Some functional flows use sudo() to create records as current user is the public user. This user has no email. Since 1e6c3bec2c5ca621344b09e58dbed535e80fb343 using sudo does not take superuser identity completely as it only bypasses access rights. It means some messages are created with public user as author, meaning no email_from. In this commit we fix some functional flows by setting a default email_from in the message composer only if a real email is found. Otherwise it will have to be set either by the template, either later in the process when creating messages or emails. closes odoo/odoo#34742 Signed-off-by: Thibault Delavallee (tde) --- addons/mail/wizard/mail_compose_message.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 1724064ab47..55cd6740b4b 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -62,11 +62,11 @@ class MailComposer(models.TransientModel): # author 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)) - else: - if 'email_from' not in result: - author = self.env['res.partner'].browse(result['author_id']) + if 'email_from' not in result and self.env.user.email: + result['email_from'] = self.env.user.email_formatted + elif 'email_from' not in result: + author = self.env['res.partner'].browse(result['author_id']) + if author.email: result['email_from'] = formataddr((author.name, author.email)) # v6.1 compatibility mode