diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 83f708ba492..5e333cc56fb 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2063,6 +2063,7 @@ class MailThread(models.AbstractModel): """ Hook to add custom behavior after having posted the message. Both message and computed value are given, to try to lessen query count by using already-computed values instead of having to rebrowse things. """ + return def _message_mail_after_hook(self, mails): """ Hook to add custom behavior after having sent an mass mailing. diff --git a/addons/mail/models/mail_thread_main_attachment.py b/addons/mail/models/mail_thread_main_attachment.py index 82ab9b7306f..cb1bb678f3b 100644 --- a/addons/mail/models/mail_thread_main_attachment.py +++ b/addons/mail/models/mail_thread_main_attachment.py @@ -16,7 +16,7 @@ class MailMainAttachmentMixin(models.AbstractModel): def _message_post_after_hook(self, message, msg_values): """ Set main attachment field if necessary """ super()._message_post_after_hook(message, msg_values) - self._message_set_main_attachment_id([ + self.sudo()._message_set_main_attachment_id([ attachment_command[1] for attachment_command in (msg_values['attachment_ids'] or []) ]) @@ -24,7 +24,7 @@ class MailMainAttachmentMixin(models.AbstractModel): def _message_set_main_attachment_id(self, attachment_ids): if attachment_ids and not self.message_main_attachment_id: # Assign one of the attachments as the main according to the following priority: pdf, image, other types. - self.sudo().with_context(tracking_disable=True).message_main_attachment_id = max( + self.with_context(tracking_disable=True).message_main_attachment_id = max( self.env['ir.attachment'].browse(attachment_ids), key=lambda r: (r.mimetype.endswith('pdf'), r.mimetype.startswith('image')) ).id