From 64ea747824dc5580f35c8af904029139ef2fb4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 24 Nov 2016 17:51:56 +0100 Subject: [PATCH] [FIX] mail: fix record model and ids management when posting using a template Posting on a document not inheriting from mail_thread was impossible due to several crashes or wrongly set variables. Some cleaning is planned in those methods as there are a lot of unnecessary computation. This will be done in another commit. Probably. --- addons/mail/models/mail_thread.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index df7ba1821e5..f0e6970bcce 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1923,15 +1923,17 @@ class MailThread(models.AbstractModel): kwargs['composition_mode'] = 'comment' if len(self.ids) == 1 else 'mass_mail' if not kwargs.get('message_type'): kwargs['message_type'] = 'notification' - res_id = self.ids[0] or 0 + res_id = kwargs.get('res_id', self.ids and self.ids[0] or 0) + res_ids = kwargs.get('res_id') and [kwargs['res_id']] or self.ids # Create the composer composer = self.env['mail.compose.message'].with_context( - active_ids=self.ids, - active_model=self._name, + active_id=res_id, + active_ids=res_ids, + active_model=kwargs.get('model', self._name), default_composition_mode=kwargs['composition_mode'], - default_model=self._name, - default_res_id=self.ids[0] or 0, + default_model=kwargs.get('model', self._name), + default_res_id=res_id, default_template_id=template_id, ).create(kwargs) # Simulate the onchange (like trigger in form the view) only