[IMP] mail: display latest records first when previewing templates

And also avoid resetting the body if there is no record chosen.

Closes #18566 .
This commit is contained in:
Prakash Prajapati
2017-10-18 13:20:39 +02:00
committed by Thibault Delavallée
parent cad52c81e3
commit e302ca7b3d
+4 -2
View File
@@ -17,7 +17,7 @@ class TemplatePreview(models.TransientModel):
if not template_id:
return []
template = self.env['mail.template'].browse(int(template_id))
records = self.env[template.model_id.model].search([], limit=10)
records = self.env[template.model_id.model].search([], order="id desc", limit=10)
records |= records.browse(default_res_id)
return records.name_get()
@@ -38,8 +38,10 @@ class TemplatePreview(models.TransientModel):
@api.onchange('res_id')
@api.multi
def on_change_res_id(self):
if not self.res_id:
return {}
mail_values = {}
if self.res_id and self._context.get('template_id'):
if self._context.get('template_id'):
template = self.env['mail.template'].browse(self._context['template_id'])
self.name = template.name
mail_values = template.generate_email(self.res_id)