首先需要在模块中创建report目录,例如官方文件所示:
其中get_report_values方法是必须写的,因为一会在xml文件中会用到对应的数据。用self.env.cr.execute()这个方法执行了原生的SQL语句。
bn_oracle_report_pzqweb.xml中
<!--测试--> <report id="action_bn_oracle_report_pzqweb3" string="凭证报表测试" model="bn.oracle.interface.pz.master" report_type="qweb-html" name="bn_oracle.report03" file="bn_oracle.report03"/>
id:外id标识
model:相关的模型显示在那个模块进行打印报表 通常在各视图中的打印那里会出现
report_type: 报表类型 是 qweb-pdf 或 qweb-html
return self._cr.dictfetchall() #返回字典型结果集
return self._cr.fetchall() #返回列表型结果集
<!--测试--> <template id="report03"> <t t-call="web.html_container"> <t t-call="web.external_layout"> <div class="page"> <table width="80%"> <tbody> <tr> <td>凭证编号: <t t-esc="heard.pz_sequence"/> </td> <td>日期: <t t-esc="heard.throw_date" t-options='{"widget": "date"}'/> </td> </tr> <tr> <td>Oracle凭证号: <t t-esc="heard.strjournalname"/> </td> <td>抛转状态: <t t-esc="heard.oracle_state"/> </td> </tr> </tbody> </table> <br/> <table class="table table-condensed" width="100%"> <thead> <th width="15%">科目</th> <th width="12%">部门</th> <th width="10%">人员</th> <th width="8%">项目</th> <th width="5%">借方</th> <th width="5%">贷方</th> <th width="45%">摘要</th> </thead> <tbody> <t t-foreach="lines_data" t-as="o"> <tr> <td> <t t-esc="o[2]"/> </td> <td> <t t-esc="o[3]"/> </td> <td> <t t-esc="o[4]"/> </td> <td> <t t-esc="o[5]"/> </td> <td> <t t-esc="o[6]" t-options='{"widget": "float", "precision": 2}'/> </td> <td> <t t-esc="o[7]" t-options='{"widget": "float", "precision": 2}'/> </td> <td> <t t-esc="o[8]"/> </td> </tr> </t> <tr> <td> </td> <td> <strong>合 计:</strong> </td> <td> </td> <td> </td> <td> <strong> <t t-esc="sum(line[6] for line in lines_data)" t-options='{"widget": "float", "precision": 2}'/> </strong> </td> <td> <strong> <t t-esc="sum(line[7] for line in lines_data)" t-options='{"widget": "float", "precision": 2}'/> </strong> </td> <td> </td> </tr> </tbody> </table> </div> </t> </t> </template>
到这里基本就ok了,可能写的比较模糊,刚开始写博客,有什么疑问可以大家讨论~
文章来源: Odoo11添加打印选项及报表