[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.
This commit is contained in:
Thibault Delavallée
2016-12-30 10:45:39 +01:00
parent 72d988cba5
commit 64ea747824
+7 -5
View File
@@ -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