diff -Naur orig/email_template/email_template.py new/email_template/email_template.py --- orig/email_template/email_template.py 2012-06-07 01:15:11.500516678 +0100 +++ new/email_template/email_template.py 2012-06-07 01:26:50.535721216 +0100 @@ -340,7 +340,9 @@ attachments = {} # Add report as a Document if template.report_template: - report_name = template.report_name + report_name = self.render_template(cr, uid, template.report_name, + template.model, res_id, context=context) \ + or False report_service = 'report.' + report_xml_pool.browse(cr, uid, template.report_template.id, context).report_name # Ensure report is rendered using template's language ctx = context.copy() @@ -395,9 +397,11 @@ 'res_model': mail_message._name, 'res_id': msg_id, } - if context.has_key('default_type'): + if context and context.has_key('default_type'): del context['default_type'] attachment_ids.append(ir_attachment.create(cr, uid, attachment_data, context=context)) + if attachment_ids: + mail_message.write(cr, uid, msg_id, { 'attachment_ids': [(6, 0, attachment_ids)]}, context=context) if force_send: mail_message.send(cr, uid, [msg_id], context=context) return msg_id