【问题标题】:Send reports automatically via email openerp通过电子邮件 openerp 自动发送报告
【发布时间】:2016-06-11 14:25:49
【问题描述】:

Odoo 有报告部分,我想知道如何(如果可能的话)通过邮件发送报告(并为其创建自动操作)?

假设我们必须crm.phonecall.report model,如何获取它的信息并在电子邮件模板中使用它?我尝试使用该模型制作电子邮件模板,然后添加与电话分析中相同的 xml 文本,但这不起作用。非常感谢所有的帮助。

【问题讨论】:

    标签: openerp


    【解决方案1】:

    以下代码足以满足您提到的要求。它调用电子邮件模板,然后附加报告附件,最后发送电子邮件。

    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 报告本身。就像它在报告->电话分析SAMPLE 中显示的那样。我想发送这些报告(使用 domain="[('date','=',time.strftime('%Y-%m-%d')),('state','=',' done')] ) 每天发送到一封电子邮件。或者是否有可能在消息中使用
    猜你喜欢
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多