Thursday, 22 September 2016

How to create custom reports in Odoo (Qweb)

Qweb Reporting Engine | To day you will learn how to create custom reports in odoo using qweb reporting engine. In this post we will learn how to create simple custom reports and its template using qweb.

What is qweb?

Qweb is a reporting engine or template engine used by odoo. By using this (qweb) we can create reports in odoo. It uses XML to create design of reports as per your need. We can also say that qweb is XML based reporting engine for OpenERP/Odoo.

1   class student_status_report_probation(models.AbstractModel):

2   _name = 'report.obe_reports_hec.report_student_on_probation'

3    @api.multi

4   def render_html(self,data=None):

5        report_obj = self.env['report']

6        print('>>>>>>>>>>.....', report_obj)

7        report = report_obj._get_report_from_name('obe_reports_hec.report_student_on_probation')

8        print('>>>>>>>>>>', report)

9        data_array = []

11      docargs = {

12            'data':data_array,

13            }

14      return report_obj.render('obe_reports_hec.report_student_on_probation', docargs)      

Here we describe important lines, In line no 1 we declare a class named  "student_status_report_probation" and here we use "AbstractModel", for creating our reports.
In line no 2 we declare the name of our report (Note: Here the important things is the name of the report should be same as the name of "template_id" which is created in xml file of the report.)
and  In line no 14 we render our "Data" to xml files.







        string="Student Status Report(Probation)"



        report_type="qweb-html" />

    <template id="report_student_on_probation">

          <t t-call="report.layout">

            <div class="page">

                <div class="text-center">

                    <h4><b>Hello This is Custom Report (Odoo QWEB)</b></h4>







Here the name of template id (report_student_on_probation) is same as the name of report (Line no 2 in file).

The screen shot of above report is given below:



  1. Replies
    1. Yes good question :) you can call that report on button click. I will share this code on Monday. Thanks

    2. @api.multi
      def view_report_button(self):
      #your logic goes here for data
      return {
      'type': '',
      'report_name': 'your_module_name.report_you_report_template_id',

      Above is the code for button to open report.