How to Create Qweb Report in Odoo 16?
Last updated: November 24, 2022 Read in fullscreen view
- 21 Apr 2021 Most frequently asked questions about Odoo ERP
- 10 Aug 2021 Build A Marketplace Website with Odoo ecommerce
- 18 May 2022 Odoo Employee Contract Portal Self Service
- 29 Nov 2019 Odoo Website Builder Allows You to Make Your Own Website
- 10 Apr 2022 Odoo Dealership Management
An ERP system contains many modules for performing various operations to run a business workflow efficiently. Despite this, every organization wants to know its progress, and they have to present the growth to their boards or authorities, which is when reports come in handy. Therefore, Odoo provides various report projections, such as PDFs, graphical presentations, pivot tables, etc.
Odoo uses Qweb as a reporting engine or template engine. By using Qweb, we can create reports in Odoo. Reports can be designed using XML as per your requirements. Odoo Qweb Report is also an OpenERP/Odoo XML based reporting engine. It allows us to manipulate data easily by using XML
In Odoo, to render PDFs from the Qweb templates, we used Wkhtmltopdf. Since the templates are defined in HTML format in the previous section, wkhtmltopdf will render the PDF report from Qweb.
Odoo reports are working with report templates and report actions. I used the report templates in report action to identify which template you want to select. When a report is printed, a report action is triggered that can either be called from the Print menu or from a Python function. You can also set a custom page format specified in your report action.
Report Action
Odoo has different kinds of actions for different operations. For example, reports are generated when the report action is triggered. The model will recognize the report action ‘ir.actions.report’ used in the record.
You can specify your report action by adding an xml file in your report directory. Here is an example of a report action.
<record id="action_report_fleet_id" model="ir.actions.report"> <field name="name">Fleet ID</field> <field name="model">fleet.fleet</field> <field name="report_type">qweb-pdf</field> <field name="report_name">fleet..report_fleet_id</field> <field name="report_file">fleet.report_fleet_id</field> <field name="print_report_name">Vehicle - %s' % (object.name)</field> <field name="binding_model_id" ref="model_fleet_fleet"/> </record>
Name: Specify the name of the report.
Model: Specify the model name here where you can fetch the data for the report. model is a mandatory field.
report_type: Here, you can specify the report type. Mainly it stores two values, qweb-pdf and qweb-html. The default value of report_type is qweb-pdf.
report_name: Here, you can specify the external_id of the report template and is a mandatory field
print_report_name: You can use python expressions to generate report filenames.
binding_model_id: If you want to print the report from the Print Action button inside a view, you can bind the action with the corresponding model.
paperformat_id: You can specify the paper format external id here. If it is not specified, take the default paper format the company will use.
Define Odoo Qweb Report Template
You can create an xml file inside your report directory. By using the HTML, the templates are designed. You can specify the structure of your report inside the <template> tag. By using the <t-call=” ”/> tag, you can call the other templates in your custom reports.
<template id="report_fleet_id"> <t t-call="web.html_container"> <t t-foreach="docs" t-as="o"> <t t-call="web.external_layout"> <div class="page"> <h2>Report title</h2> <p>This object's name is <span t-field="o.name"/></p> </div> </t> </t> </t> </template>
The Id report_fleet_id is the external id which you specify inside your report action. For example, you can specify the header and footer of your report by using <header> and <footer> tags, or you can call an external id by using the <t-call=” ”/> tags.
You can also generate qweb reports from the wizard. Thus in odoo, one can easily create/custom qweb reports.
If you plan a new ERP Software implementation and you have heard about Odoo and got attracted by the Odoo ERP platform, decided to use it but don’t have time, resources, or knowledge to manage this yourself, thereby looking for professional help, then you have come to a right place. TIGO has implemented and delivered our own customized Odoo applications with minimal Odoo implementation cost for more than 5 years.