In this article you will learn how to create a report in odoo from scratch using Qweb reporting engine. You will also learn how to use and create variables, loops, conditions in QWEB reporting template.
How to Create QWEB Report in Odoo | OpenERP
In Odoo we can create reports using HTML/QWEB. QWEB is a templating engine which is used to generate HTML pages or templates frames. In this example we are going to pass or render report data to our QWEB XML template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<table class="table report_border table-hover table-striped"> | |
<thead> | |
<tr> | |
<th style="padding: 0px;" class="text-center"><h5><b>Heading 1</b></h5></th> | |
<th style="padding: 0px;" class="text-center"><h5><b>Heading 2</b></h5></th> | |
<th style="padding: 0px;" class="text-center"><h5><b>Heading 3</b</h5></th> | |
</tr> | |
</thead> | |
<tbody> | |
<t t-foreach="data" t-as="d"> | |
<tr> | |
<td class="text-center" style="vertical-align:middle;"> | |
<span t-esc="d.field_1"/> | |
</td> | |
<td class="text-center" style="vertical-align:middle;"> | |
<span t-esc="d.field_2"/> | |
</td> | |
<td class="text-center" style="vertical-align:middle;"> | |
<span t-esc="d.field_3"/> | |
</td> | |
</tr> | |
</t> | |
</tbody> | |
</table> | |
</div> | |
create_qweb_report_openerp_odoo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# custom report | |
class custom_report_class(models.AbstractModel): | |
_name = 'report.module_name.my_custom_report' | |
@api.multi | |
def render_html(self,data=None): | |
report_obj = self.env['report'] | |
report = report_obj._get_report_from_name('module_name.my_custom_report') | |
model_obj = self.env['your.model.name'].sudo().search([('id', '=', self._ids[0])]) | |
docargs = { | |
'data': model_obj, | |
} | |
return report_obj.render('module_name.my_custom_report', docargs) | |
Read More: How to hide export option from more menu in odoo
How to Check Condition in QWEB Templates
<t t-if="condition"><p>Test</p></t>
How to Display Data Output in QWEB Template
<p><t t-esc="value"/></p>
How to Print Values in Loop in QWEB Template
<t t-foreach="[1, 2, 3]" t-as="i"><p><t t-esc="i"/></p></t>
How to Create Variables in QWEB Template
<t t-set="existing_variable" t-value="False"/>
1 Comments
how to print report from button?
ReplyDelete