Odoo有报告部分,我想知道如何(如果可能的话)通过邮件发送报告(并为其创建自动化操作)?
我们必须说crm.phonecall.report model
,如何获取信息并在电子邮件模板中使用它?我尝试使用该模型制作电子邮件模板,然后在Phonecall Analysis中添加相同的xml文本,但这并不起作用。所以所有的帮助都非常感谢。
答案 0 :(得分:0)
以下代码足以满足您提到的要求。它调用电子邮件模板,然后附加报告附件,最后发送电子邮件。
email = email_obj.browse(cr, uid, template_id)
attachment_obj = self.pool.get('ir.attachment')
ir_actions_report = self.pool.get('ir.actions.report.xml')
matching_reports = ir_actions_report.search(
cr, uid, [('name', '=', 'Report_Name_here')])
if matching_reports:
report = ir_actions_report.browse(cr, uid, matching_reports[0])
report_service = 'report.' + report.report_name
service = netsvc.LocalService(report_service)
(result, format) = service.create(
cr, uid, mrp_ids, {'model': self._name, 'start_date': start, 'end_date': end}, context=context)
if not report.attachment:
file_name = "Production Sale Report " + datetime.strftime(datetime.now().date(), "%Y-%m-%d") + ".pdf"
attachment_id = attachment_obj.create(cr, uid,
{
'name': file_name,
'datas': result,
'datas_fname': file_name,
'type': 'binary'
}, context=context)
email_obj.write(cr, uid, template_id, {'email_from': email.email_from,
'email_to': email.email_to,
'subject': email.subject,
'body_html': email.body_html,
'email_recipients': email.email_recipients,
'attachment_ids': [(6, 0, [attachment_id])],
})
email_obj.send_mail(cr, uid, template_id, False, True, context=context)
希望这能解决您的问题。干杯