odoo 报表


报表的基本格式定义

打印报表

在odoo14中

Odoo 使用基于 QWeb模板, BootstrapWkhtmltopdf 来实现的。

报告是两个要素的组合:

  • ir.actions.report它配置报表的各种基本参数(默认类型,报表是否应在生成后保存到数据库,…)。
  • 基本上是一个标准的写法,下面是一个示例。可以写在一个xml中。
<record id="account_invoices" model="ir.actions.report">
    <field name="name">Invoices</field>
    <field name="model">account.invoice</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">account.report_invoice</field>
    <field name="report_file">account.report_invoice</field>
    <field name="attachment_use" eval="True"/>
    <!--文件名称-->
    <field name="attachment">(object.state in ('open','paid')) and
        ('INV'+(object.number or '').replace('/','')+'.pdf')</field>
    <field name="binding_model_id" ref="model_account_invoice"/>
    <field name="binding_type">report</field>
</record>

标准QWeb视图关于实际报告:

<t t-call="web.html_container">
    <t t-foreach="docs" t-as="o">
        <t t-call="web.external_layout">
            <div class="page">
                <h2>Report title</h2>
            </div>
        </t>
    </t>
</t>

标准呈现上下文提供了一些元素,最重要的是:

  • docs

    打印报告的记录

  • user

    用户打印报表

在odoo13中

report 的 template

report标签可用于定义一条报表记录。属性有:

  1. id

生成的数据的id。

  1. name (必选)

报表名,用于查找及描述。

  1. model (必选)

报表记录所对应的模型。

  1. report_type (必选)

qweb-pdf| qweb-html

  1. report_name

输出pdf时文件名。

  1. groups

用于指定可以查看、使用该报表的用户组。

  1. attachment_use

如果设置为true时,该报表会以记录的附件的形式保存,一般用于一次生成、多次使用的报表。

  1. attachment

用于定义报表名的python表达式,使记录可以通过object对象访问。

  1. paperformat

用于打印报表的文件格式的外部id(默认是公司的格式. (可以自定义格式. 。

<odoo>
<template id="report_demo_odoo_tutorial">
        <t t-call="web.html_container"> 
            <t t-foreach="docs" t-as="o">  # 上面的格式是固定的,重命名为 o 
                <t t-call="web.external_layout">
                    <div class="page">
                        <h2>Odoo Report</h2>
                        <div>
                            <strong>Name:</strong>
                            <p t-field="o.name"/> # o 可以想象成一个物件,物件的名称。
                        </div>
                        <div>
                            <strong>Name_track_always:</strong>
                            <p t-field="o.name_track_always"/>
                        </div>
                    </div>
                </t>
            </t>
        </t>
    </template>
    
    ## 这里才是设置的部分,
 <report
        id="action_report_demo"
        string="Demo Report"
        model="demo.odoo.tutorial"  # 采用的是这个model这个模块的数据
        report_type="qweb-pdf" # 使用的格式。
        name="demo_odoo_tutorial.report_demo_odoo_tutorial"  # 文件夹位置,模块名称,+ 模板id。
        file="demo_odoo_tutorial.report_demo_odoo_tutorial"
        print_report_name="'Demo Report - %s' % ((object.name).replace('/', ''))"  # 这里的objece就是模型的名称.name为里面存在的字段名。
        paperformat="catalog_deal.paperformat_odoo3" # 这里就是record field的id,catalog_deal为你的项目名称。
    />
</odoo>

其他:

<report
    id="account_invoices"
    model="account.invoice"  # 报表记录所对应的模型。
    string="Invoices"  # 显示的名称
    report_type="qweb-pdf" # 生成的文件格式,有很多种的。
    name="account.report_invoice" # 下载的文件名称
    file="account.report_invoice" # 不知道是什么,和name同名。
    attachment_use="True"
    attachment="(object.state in ('open','paid')) and
        ('INV'+(object.number or '').replace('/','')+'.pdf')" //拼接文件名,object 为模型名称。
/>

报表格式

报表格式用report.paperformat记录来定义,**字段**有:

  1. name (必选)

用于查找及区分的名字。

  1. description

格式的描述。

  1. format

一个预定义的纸张大小格式如(A0-A9,B0-B10等. 或自定义custom,默认是A4。

  1. dpi

输出的DPI,默认90。

  1. margin_top, margin_bottom, margin_left, margin_right

以 mm 为单位的margin值。

  1. page_height, page_width

以 mm 为单位的页面宽高尺寸值。

  1. orientation

纸张横向或纵向打印。

  1. Landscape , Portrait header_line

boolean类型,是否显示标题行。

  1. header_spacing

以 mm 为单位的头部空白尺寸。

<record id="paperformat_frenchcheck" model="report.paperformat">
    <field name="name">French Bank Check</field>
    <field name="default" eval="True"/>
    <field name="format">custom</field>
    <field name="page_height">80</field>
    <field name="page_width">175</field>
    <field name="orientation">Portrait</field>
    <field name="margin_top">3</field>
    <field name="margin_bottom">3</field>
    <field name="margin_left">3</field>
    <field name="margin_right">3</field>
    <field name="header_line" eval="False"/>
    <field name="header_spacing">3</field>
    <field name="dpi">80</field>
</record>

文章作者: theing
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 theing !
评论
  目录