Odoo 10 Qweb 报告,为 PDF 文件定义文件名

Odoo 10 Qweb Report, define filename for PDF file

我有以下自定义报告:

<?xml version="1.0"?>
<odoo>
  <report
        id = "report_custom_sale_order"
        name = "custom_saleorder_v2.custom_report_saleorder"
        string = "Custom Quotation / Order"
        model = "sale.order"
        report_type = "qweb-pdf"
        report_name = "((object.number or 'SaleOrder').replace('/','')+'.pdf')"
        attachment_use = "False"
  />

</odoo>

我希望将 PDF 下载为 SO003.pdf reference/sequential SO003 的销售订单,以及 SaleOrder.pdf 未分配 [=] 的草稿销售订单35=].

当我尝试使用 report_name 实现此类行为时,出现以下错误:

AssertionError: Element odoo has extra content: report, line 11

如何使用report_name


我尝试了以下 CZoellner 评论:

<?xml version="1.0"?>
<odoo>
    <report
        id = "report_custom_sale_order"
        name = "custom_saleorder_v2.custom_report_saleorder"
        string = "Custom Quotation / Order"
        model = "sale.order"
        report_type = "qweb-pdf"
        attachment_use = "False"
    />
    <record id="report_custom_sale_order" model="ir.actions.report.xml">
        <field name="print_report_name"><![CDATA[((object.number or 'SaleOrder').replace('/','')+'.pdf')]]></field>
    </record>
</odoo>

我收到以下错误:

ParseError: "null value in column "name" violates not-null constraint
DETAIL:  Failing row contains (523, 1, null, 1, 2018-02-13 17:17:20.385168, null, 2018-02-13 17:17:20.385168, ir.actions.report.xml, null, null, t, pdf, null, null, null, null, null, t, null, f, null, null, null, f, null, null, ((object.number or 'SaleOrder').replace('/','')+'.pdf')).
" while parsing /usr/lib/python2.7/dist-packages/odoo/custom_addons/custom_saleorder_v2/reports/sale_report.xml:12, near
<record id="report_custom_sale_order" model="ir.actions.report.xml">
    <field name="print_report_name">((object.number or 'SaleOrder').replace('/','')+'.pdf')</field>
</record>

注意:如果我使用 object.name 而不是 object.number 也是一样的(我认为这是获取文档 reference/sequential 的正确方法。

您正在为报表名称和对象使用不同的字段。我已经使用正确的字段名称更新了您的代码。

<?xml version="1.0"?>
<odoo>
  <report
        id = "report_custom_sale_order"
        name = "custom_saleorder_v2.custom_report_saleorder"
        string = "Custom Quotation / Order"
        model = "sale.order"
        report_type = "qweb-pdf"
        print_report_name = "((object.name or 'SaleOrder').replace('/','')+'.pdf')"
        attachment_use = "False"
  />

希望对您有所帮助。

您可以使用 print_report_name.

<?xml version="1.0"?>
<odoo>
    <report id = "report_custom_sale_order"
            name = "custom_saleorder_v2.custom_report_saleorder"
            string = "Custom Quotation / Order"
            model = "sale.order"
            report_type = "qweb-pdf"
            print_report_name = "((object.number or 'SaleOrder').replace('/','')+'.pdf')"
            attachment_use = "False" />
</odoo>

在数据 XML 中使用特殊标记 report 时,字段 print_report_name 未转换。因此,只需在之后添加具有正常 XML 记录的字段:

<?xml version="1.0"?>
<odoo>
    <report
            id = "report_custom_sale_order"
            name = "custom_saleorder_v2.custom_report_saleorder"
            string = "Custom Quotation / Order"
            model = "sale.order"
            report_type = "qweb-pdf"
            attachment_use = "False"
    />
    <record id="custom_module_name.report_custom_sale_order" model="ir.actions.report.xml">
        <field name="print_report_name"><![CDATA[((object.number or 'SaleOrder').replace('/','')+'.pdf')]]></field>
    </record>
</odoo>

Odoo 10, but in Odoo 11 添加的字段中没有转换。