[FIX] mail: onchange_template_id

When using context action for a template, the report was not shown in
the compose message as an attachment.

opw:657152
This commit is contained in:
Goffin Simon
2016-01-21 14:36:20 +01:00
parent cda0b10401
commit dc02f773ce
2 changed files with 23 additions and 2 deletions
+1 -1
View File
@@ -493,7 +493,7 @@ class MailTemplate(models.Model):
)
# Add report in attachments: generate once for all template_res_ids
if template.report_template:
if template.report_template and not 'report_template_in_attachment' in self.env.context:
for res_id in template_res_ids:
attachments = []
report_name = self.render_template(template.report_name, template.model, res_id)
+22 -1
View File
@@ -188,7 +188,7 @@ class MailComposer(models.TransientModel):
@api.multi
def send_mail_action(self):
# TDE/ ???
return self.send_mail()
return self.with_context(report_template_in_attachment=True).send_mail()
@api.multi
def send_mail(self, auto_commit=False):
@@ -346,6 +346,20 @@ class MailComposer(models.TransientModel):
if template.user_signature and 'body_html' in values:
signature = self.env.user.signature
values['body_html'] = tools.append_content_to_html(values['body_html'], signature, plaintext=False)
if template.report_template:
attachment = self.env['ir.attachment']
attach = self.generate_attachment_from_report(template_id, res_id)
for attach_fname, attach_datas in attach[res_id].pop('attachments', []):
data_attach = {
'name': attach_fname,
'datas': attach_datas,
'datas_fname': attach_fname,
'res_model': 'mail.compose.message',
'res_id': 0,
'type': 'binary',
}
values.setdefault('attachment_ids', list()).append(attachment.create(data_attach).id)
elif template_id:
values = self.generate_email_for_composer(template_id, [res_id])[res_id]
# transform attachments into attachment_ids; not attached to the document because this will
@@ -376,6 +390,13 @@ class MailComposer(models.TransientModel):
return {'value': values}
@api.multi
def generate_attachment_from_report(self, template_id, res_id):
fields = ['attachment_ids']
result = self.env['mail.template'].with_context(tpl_partners_only=True).browse(template_id).generate_email([res_id], fields=fields)
return result
@api.multi
def save_as_template(self):
""" hit save as template button: current form value will be a new