0
Odoo有报告部分,我想知道如何(如果它甚至可能)通过邮件发送报告(并为其创建自动操作)?通过电子邮件自动发送报告openerp
假设我们必须crm.phonecall.report model
,如何获取信息并在电子邮件模板中使用它?我尝试使用该模型制作电子邮件模板,然后添加与Phonecall分析中相同的XML文本,但这不起作用。所以所有的帮助真的很感激。
Odoo有报告部分,我想知道如何(如果它甚至可能)通过邮件发送报告(并为其创建自动操作)?通过电子邮件自动发送报告openerp
假设我们必须crm.phonecall.report model
,如何获取信息并在电子邮件模板中使用它?我尝试使用该模型制作电子邮件模板,然后添加与Phonecall分析中相同的XML文本,但这不起作用。所以所有的帮助真的很感激。
以下代码将足以满足您提到的要求。它调用电子邮件模板,然后附加一个报告附件,最后发送一封电子邮件。
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)
希望这能解决您的问题。干杯
我更想知道如何编写QWeb报告本身。就像它在报告 - >电话分析[示例](http://i.imgur.com/juyqgs1.png)中所示。我希望发送这些报告(使用domain =“[('date','=',time.strftime('%Y-%m-%d')),('state','=','完成')])每天发送一封电子邮件,或者在邮件中使用 ? –