標籤: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中產生二維碼,然後在產生報表時嵌入:

還可以使用查詢url來傳多個參數:<img t-att-src="‘/report/barcode/? type=%s&value=%s&width=%s&height=%s‘%(‘QR‘, ‘text‘, 200, 200)"/>
odoo10學習筆記十三:qweb報表