odoo10學習筆記十三:qweb報表

來源:互聯網
上載者:User

標籤:port   name   ext   需要   對象   完成   二維   標籤   code   

一:概述

報表是使用qweb定義的,報表的pdf匯出是使用wkhtmltopdf來完成的。

如果需要為一個模型建立報表,需要定義report及對應模板。

如果有需要的話還可以指定特定的紙張格式,

如果需要訪問其他模型,就需要定義Custom Report。

 

二:Report

report標籤可用於定義一個報表:

id - 產生的資料的idname (必選) - 報表名用於尋找及描述model (必選) - 報表所對應的模型report_type (必選) - qweb-pdf: pdf | qweb-html : htmlreport_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)"/>

 

odoo10學習筆記十三:qweb報表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.