From 351b0ca6f4f493fed3542c8f52e8ec70ee622b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 29 Nov 2019 10:31:52 +0000 Subject: [PATCH] [IMP] mail: improve returned values of _message_compute_author Purpose of this commit is to ease the use of mail.thread tool method _message_compute_author. Instead of returning a dict with two values and having to unpack them, directly return a tuple with both author and email_from values. All calls and return management are the same in mail. Let us simplify code. Task ID 1853147 PR #32243 --- addons/mail/models/mail_thread.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index ac7442fa13e..0c53cbad6b1 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1827,8 +1827,7 @@ class MailThread(models.AbstractModel): raise ValueError('message_post partner_ids and channel_ids must be integer list, not commands') # Find the message's author - author_info = self._message_compute_author(author_id, email_from, raise_exception=True) - author_id, email_from = author_info['author_id'], author_info['email_from'] + author_id, email_from = self._message_compute_author(author_id, email_from, raise_exception=True) if not subtype_id: subtype = subtype or 'mt_note' @@ -1973,8 +1972,7 @@ class MailThread(models.AbstractModel): msg_kwargs = dict((key, val) for key, val in kwargs.items() if key in self.env['mail.message']._fields) notif_kwargs = dict((key, val) for key, val in kwargs.items() if key not in msg_kwargs) - author_info = self._message_compute_author(author_id, email_from, raise_exception=True) - author_id, email_from = author_info['author_id'], author_info['email_from'] + author_id, email_from = self._message_compute_author(author_id, email_from, raise_exception=True) if not partner_ids: _logger.warning('Message notify called without recipient_ids, skipping') @@ -2013,8 +2011,7 @@ class MailThread(models.AbstractModel): the log process. This method should be called within methods where access rights are already granted to avoid privilege escalation. """ self.ensure_one() - author_info = self._message_compute_author(author_id, email_from, raise_exception=False) - author_id, email_from = author_info['author_id'], author_info['email_from'] + author_id, email_from = self._message_compute_author(author_id, email_from, raise_exception=False) message_values = { 'subject': subject, @@ -2038,8 +2035,7 @@ class MailThread(models.AbstractModel): :param bodies: dict {record_id: body} """ - author_info = self._message_compute_author(author_id, email_from, raise_exception=False) - author_id, email_from = author_info['author_id'], author_info['email_from'] + author_id, email_from = self._message_compute_author(author_id, email_from, raise_exception=False) base_message_values = { 'subject': subject, @@ -2079,10 +2075,7 @@ class MailThread(models.AbstractModel): if not email_from and not self.env.su and raise_exception: raise exceptions.UserError(_("Unable to log message, please configure the sender's email address.")) - return { - 'author_id': author_id, - 'email_from': email_from, - } + return author_id, email_from def _message_create(self, values_list): if not isinstance(values_list, (list)):