簡単なレポートを作成するには、次の手順を実行します。
レポート xml ファイルの定義
/addons/example/views/example_report.xml
で参照して、アドオンに xml ファイルをロードします。
/addons/example/__openerp__.py
他のxmlファイルと一緒にデータセクションに。
'data': ['views/example_report.xml'],
- アドオンを更新します。
アドオンのリスト ビューでレコードを選択し (チェックボックスをオンにする)、[詳細] ドロップダウンでレポートを実行できるはずです。または、モデルのフォーム ビューでさらにクリックして、そこからレポートを実行することもできます。
注: これを機能させるには、wkhtmltopdf を適切にインストールする必要があります。wkhtmltopdf.org に説明があります (少なくともバージョン 0.12.1 を確認してください)。
簡単な xml レポート定義を次に示します。名前 (char) とサブレコード (one2many) を持つ架空のモデル example.model_name があり、サブレコード モデルには id、name、および date フィールドがあると仮定します。
<openerp>
<data>
<report
id="report_example_model_name"
model="example.model_name"
string="Example Report"
name="example.report_example_report_view"
file="example.report_model_name"
report_type="qweb-pdf"/>
<template id="report_example_report_view">
<t t-call="report.html_container">
<!-- REMEMBER, docs is the selected records either in form view or checked in list view (usually). So the line below says use the following template for each record that has been selected. -->
<t t-foreach="docs" t-as="doc">
<t>
<div class="page">
<h1>Report For <t t-esc="doc.name"/></h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Date</th>
</tr>
<t t-foreach="doc.subrecord" t-as="o">
<tr>
<td><t t-esc="o.id"/></td>
<td><t t-esc="o.name"/></td>
<td><t t-esc="o.date"/></td>
</tr>
</t>
</table>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>