邮件模板与报告

时间:2017-07-09 05:38:29

标签: openerp odoo-10

我为自定义模块创建了一个报告和邮件模板。两者都独立工作。如果我尝试使用电子邮件模板附加报告,则会收到错误:

ParseError: "insert or update on table "mail_template" violates foreign key constraint "mail_template_report_template_fkey" DETAIL: Key (report_template)=(317) is not present in table "ir_act_report_xml".

这是我的代码:

email_template.xml

<record id="email_template_edi_project" model="mail.template">
      <field name="name">Project Quotation - Send by Email</field>
      <field name="email_from">${(object.user_id.email and '%s &lt;%s&gt;' % (object.user_id.name, object.user_id.email) or '')|safe}</field>
      <!-- <field name="subject">${object.company_id.name} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' })</field> -->
      <field name="subject">Request for Project: ${object.name or 'n/a' }</field>
      <field name="partner_to">${object.partner_id.id}</field>
      <field name="model_id" ref="project_quotation.model_project_quotation"/>
      <field name="auto_delete" eval="True"/>
      <field name="report_template" ref="project_quotation.report_rfp"/>
      <field name="report_name">${(object.name or '').replace('/','_')}${object.state == 'draft' and '_draft' or ''}</field>
      <field name="lang">${object.partner_id.lang}</field>
      <field name="body_html"><![CDATA[]></field>

report_template.xml

    <report
id="project_quotation"
model="project.quotation"
string="Project Quotation"
report_type="qweb-pdf"
name="mymodule.report_rfp"
file="mymodule.report_rfp"
menu="True"/>

<template id="report_rfp">
<t t-call="report.html_container">
    <t t-foreach="docs" t-as="o">
        <t t-call="report.external_layout">
            <div class="page">
                <h2>Report title</h2>
                <p>This object's name is <span t-field="o.name"/></p>
            </div>
        </t>
    </t>
</t>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您在电子邮件模板中使用了错误的报告参考。

尝试在电子邮件模板中使用此行:

<field name="report_template" ref="project_quotation.project_quotation"/>

更一般和公开的例子是添加例如交货单转到库存拣选操作的电子邮件模板:

  1. 投放单的ID可见here
  2. 因此,报告模板参考号为stock.action_report_delivery
  3. 型号ID为stock.model_stock_picking
  4. 所以记录条目是这样的:

    <record id="stock_picking_template_email" model="mail.template">
      <field name="name">Delivery Slip E-Mail Template</field>
      <field name="email_from">${object.company_id and object.company_id.email or ''}</field>
      <field name="subject">Delivery Slip ${object.name}</field>
      <field name="partner_to">${object.partner_id.id}</field>
      <field name="lang">${object.lang}</field>
      <field name="model_id" ref="stock.model_stock_picking"/> 
      <field name="report_template" ref="stock.action_report_delivery"/>
      <field name="report_name">Delivery Slip ${object.name}</field>
      <field name="auto_delete" eval="True"/>
      <field name="body_html">
        <![CDATA[
          ...
        ]]>
      </field>
    </record>
    

    另一个很棒的电子邮件模板教程可以帮助我很多here