diff options
| author | Thibault Delavallée <tde@odoo.com> | 2019-04-24 10:25:09 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-11-29 13:35:14 +0000 |
| commit | 1838191eece59051805862ed6ce914bf5e5d1efb (patch) | |
| tree | 75955be7412a59bd7463bf4b61116b5711141352 /addons/mail/wizard | |
| parent | b9a22d2f24e587894c12bf7ad289fcddcea8a823 (diff) | |
[REF] mail, various: improve mail creation calls, notably author and email from default computation
Purpose of this commit is to correctly compute author_id and email_from
in mail_message and mail_mail as they depends from each other. Moreover it
is a good idea in various flows to specify email and author when giving
creation values to avoid default computation that is not always guaranteed to
be accurate notably when involving super user.
Mail message creation could lead to desynchronized values between author
and email_from. This is improved with this commit by correctly inheriting
from default_get and computing both of them at the same time instead of having
two default values. Indeed they depend on each other.
Same thing is done for mail composer. Mail Thread offers a tool method to
find email_from / author_id based on having one of those values or current
user and it is called whenever necessary.
Some calls to mail template send_mail are also cleaned.
Task ID 1853147
PR #32243
Diffstat (limited to 'addons/mail/wizard')
| -rw-r--r-- | addons/mail/wizard/invite.py | 5 | ||||
| -rw-r--r-- | addons/mail/wizard/mail_compose_message.py | 16 |
2 files changed, 12 insertions, 9 deletions
diff --git a/addons/mail/wizard/invite.py b/addons/mail/wizard/invite.py index 44a68a92bb9..78bf03dd776 100644 --- a/addons/mail/wizard/invite.py +++ b/addons/mail/wizard/invite.py @@ -5,6 +5,7 @@ from lxml import etree from lxml.html import builder as html from odoo import _, api, fields, models +from odoo.exceptions import UserError class Invite(models.TransientModel): @@ -47,7 +48,9 @@ class Invite(models.TransientModel): send_mail = fields.Boolean('Send Email', default=True, help="If checked, the partners will receive an email warning they have been added in the document's followers.") def add_followers(self): - email_from = self.env['mail.message']._get_default_from() + if not self.env.user.email: + raise UserError(_("Unable to post message, please configure the sender's email address.")) + email_from = self.env.user.email_formatted for wizard in self: Model = self.env[wizard.res_model] document = Model.browse(wizard.res_id) diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 193f7faf38b..d3b0e6f16bf 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -54,14 +54,14 @@ class MailComposer(models.TransientModel): result = super(MailComposer, self).default_get(fields) # author - if 'author_id' not in result: - result['author_id'] = self.env.user.partner_id.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'] = tools.formataddr((author.name, author.email)) + missing_author = 'author_id' in fields and 'author_id' not in result + missing_email_from = 'email_from' in fields and 'email_from' not in result + if missing_author or missing_email_from: + author_id, email_from = self.env['mail.thread']._message_compute_author(result.get('author_id'), result.get('email_from'), raise_exception=False) + if missing_email_from: + result['email_from'] = email_from + if missing_author: + result['author_id'] = author_id result['composition_mode'] = result.get('composition_mode', 'comment') result['model'] = result.get('model', self._context.get('active_model')) |
