Odoo 10 Qweb报告,定义PDF文件的文件名 [英] Odoo 10 Qweb Report, define filename for PDF file

查看:285
本文介绍了Odoo 10 Qweb报告,定义PDF文件的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下自定义报告:

<?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>

我希望将具有参考/顺序为SO003的销售订单的PDF下载为SO003.pdf,而对于未分配参考/顺序的草稿中的销售订单,将PDF下载为SaleOrder.pdf.

I would like the PDF to be downloaded as SO003.pdf for sales order with reference/sequential SO003, and as SaleOrder.pdf for sales order in draft without assigned reference/sequential.

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

When I try to implement such behaviour with report_name I get the following error:

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

应如何使用report_name?

在我尝试过的CZoellner评论之后:

Following CZoellner comment I tried:

<?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(我认为这是获取文档的引用/顺序的正确方法.

Note: it is the same if I use object.name instead of object.number (which I think it is the right way of getting the reference/sequential of the document.

推荐答案

在数据XML中使用特殊标记report时,不会转换字段print_report_name.因此,之后只需添加具有常规XML记录的字段即可:

The field print_report_name is not converted while using the special tag report in data XMLs. So just add the field with normal XML record afterwards:

<?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 Odoo 10 ,但在 Odoo 11 字段中已添加.

It's not converted in Odoo 10, but in Odoo 11 the field was added.

这篇关于Odoo 10 Qweb报告,定义PDF文件的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆