zoukankan      html  css  js  c++  java
  • odoo10学习笔记十三:qweb报表

    原文地址:http://www.cnblogs.com/ygj0930/p/7151732.html

    一:概述

    报表是使用qweb定义的,报表的pdf导出是使用wkhtmltopdf来完成的。

    如果需要为一个模型创建报表,需要定义report及对应模板

    如果有需要的话还可以指定特定的纸张格式

    如果需要访问其他模型,就需要定义Custom Report。

     

    二:Report

    report标签可用于定义一个报表:

    复制代码
    id - 生成的数据的id
    name (必选) - 报表名用于查找及描述
    model (必选) - 报表所对应的模型
    report_type (必选) - qweb-pdf: pdf | qweb-html : html
    report_name - 输出pdf时文件名
    groups - Many2many字段用于指定可以查看使用该报表的用户组
    attachment_use - 如果设置为true时,该报表会以记录的附件的形式保存,一般用于一次生成多次使用的报表
    attachment - 用于定义报表名的python表达式,记录可以通过object对象访问
    paperformat - 用于打印报表的文件格式的外部id(默认是公司的格式)(可以自定义格式)
    复制代码
    复制代码
    <report
        id="account_invoices"
        model="account.invoice"
        string="Invoices"
        report_type="qweb-pdf"
        name="account.report_invoice"
        file="account.report_invoice"
        attachment_use="True"
        attachment="(object.state in ('open','paid')) and
            ('INV'+(object.number or '').replace('/','')+'.pdf')" //拼接文件名
    />
    复制代码


    三:报表模板

    复制代码
    <template id="report_invoice">
        <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>
    </template>
    复制代码

    通过调用external_layout来给报表添加默认的头部和尾部pdf内容会是<div class="page">里的内容

    模板id需与报表声明中一致,比如上面的account.report_invoice,由于这是qweb模板,可以在docs对象中取得字段内容。

     

    四:报表嵌入二维码

    在controller中生成二维码,然后在生成报表时嵌入:

    ![]('/report/barcode/QR/%s' % 'My text in qr code')
    还可以使用查询url来传多个参数:<img t-att-src="'/report/barcode/?
        type=%s&value=%s&width=%s&height=%s'%('QR', 'text', 200, 200)"/>

     

    五:报表格式

    文件格式用report.paperformat记录来定义:

    复制代码
    name (必选) - 用于查找及区分的名字
    description - 格式的描述
    format - 一个预定义的格式如(A0-A9,B0-B10等)或自定义,默认是A4
    dpi - 输出的DPI,默认90
    margin_top, margin_bottom, margin_left, margin_right - mm为单位的margin值
    page_height, page_width - mm为单位的尺寸
    orientation - 横向或纵向 Landscape , Portrait
    header_line - boolean,是否显示标题行
    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>
    
    复制代码

     

    六:查看报表

    报表是标准的web页面,所以可以通过链接直接访问:

    html版本报表可以通过 : http://localhost:8069/report/html/报表名/1

    pdf版本通过 : http://localhost:8069/report/pdf/报表名/1

  • 相关阅读:
    Fix the Package System is Broken error in Ubuntu
    linux源镜像网站
    VS2010快捷键大全
    自定义函数与存储过程的比较
    vbcr,vblf和 vbcrlf之间的区别?
    GridView序号问题
    Outlook2007设置备份账号、联系人和个性签名的方法
    c#.net4.0利用odac连接oracle取数
    无法打开登录所请求的数据库DbName 。登录失败。 用户 'IIS APPPOOL\DefaultAppPool' 登录失败。 的解决方案
    C#开发和调用Web Service
  • 原文地址:https://www.cnblogs.com/qjtjh/p/8269711.html
Copyright © 2011-2022 走看看