How to Create Qweb Report in Odoo 16?


How to Create Qweb Report in Odoo 16?

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.


Phát triển phần mềm theo yêu cầu, chi phí thấp, chất lượng cao và đặc biệt chúng tôi luôn đồng hành và phát triển cùng khách hàng trên hành trình chuyển đổi số toàn diện, giúp doanh nghiệp khách hàng bứt phá và thành công. Streamline Your Business with Outsourcing. We provide ongoing support and training to our remote teams to ensure they are equipped with the latest knowledge and skills needed to excel in their roles. We also have a full team of experts who can help you guide and help your outsourced team members who work from home.