diff options
Diffstat (limited to 'addons/mail/wizard/mail_compose_message.py')
| -rw-r--r-- | addons/mail/wizard/mail_compose_message.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 6ea72c16ed5..cc2dff25f38 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -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): @@ -216,8 +216,8 @@ class MailComposer(models.TransientModel): if wizard.template_id: # template user_signature is added when generating body_html # mass mailing: use template auto_delete value -> note, for emails mass mailing only - Mail = Mail.with_context(mail_notify_user_signature=False, mail_auto_delete=wizard.template_id.auto_delete, mail_server_id=wizard.template_id.mail_server_id.id) - ActiveModel = ActiveModel.with_context(mail_notify_user_signature=False) + Mail = Mail.with_context(mail_notify_user_signature=False, mail_server_id=wizard.template_id.mail_server_id.id) + ActiveModel = ActiveModel.with_context(mail_notify_user_signature=False, mail_auto_delete=wizard.template_id.auto_delete) if not hasattr(ActiveModel, 'message_post'): ActiveModel = self.env['mail.thread'].with_context(thread_model=wizard.model) if wizard.composition_mode == 'mass_post': @@ -288,8 +288,8 @@ class MailComposer(models.TransientModel): # always keep a copy, reset record name (avoid browsing records) mail_values.update(notification=True, model=self.model, res_id=res_id, record_name=False) # auto deletion of mail_mail - if 'mail_auto_delete' in self._context: - mail_values['auto_delete'] = self._context.get('mail_auto_delete') + if self.template_id and self.template_id.auto_delete: + mail_values['auto_delete'] = True # rendered values using template email_dict = rendered_values[res_id] mail_values['partner_ids'] += email_dict.pop('partner_ids', []) @@ -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 @@ -377,6 +391,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 template attached to the current document. """ |
