1.首先在xml文件中注册一个报表
<
report
id="qweb_test_report" model="qweb.test" string="Report Test" report_type="qweb-pdf"
name="qweb_test.test_report" file="qweb_test.test_report"/>
report_type 有两个值,qweb-pdf,qweb-html
2.创建报表类
class qweb_print(models.AbstractModel): _name="report.qweb_test.test_report" @api.multi def get_name(self): return [self.env['qweb.test'].browse(self.ids)] @api.multi def render_html(self,data=None): report_obj = self.env['report'] report = report_obj._get_report_from_name('qweb_test.test_report') records = self.get_name() docargs={ "doc_ids":self.ids, "doc_model":report.model, "docs":records, } return report_obj.render('qweb_test.test_report',docargs)
3.创建报表布局文件 template:
<template id="test_report"> <t t-call="report.html_container"> <t t-foreach="docs" t-as="o"> <div class="page"> <div class="row"> <div class="col-xs-12 text-center"> <t t-esc="o.name"/> </div> </div> </div> </t> </t> </template>