Odoo Latest Blogs

Odoo Latest Blogs | Qweb Operations in Odoo

What is qweb?

Qweb is a reporting engine or template engine used by odoo. By using this (qweb) we can create reports in odoo. Also 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.By using Qweb, we can manipulate the data very easily.

Create Qweb Reports In Odoo 12

Step 1 : Define the Report through <report> tag with following configuration.

Report tag is in the file whose name should be <module_name>_report.xml which         we have to add in ‘data’ list of






string=”Quotation Print”



name=”module_name .report_quotation



Unique identifier of report which is declared in


It is name of the report which is displayed in view of the list of print button.


Model for which we want to create report.


Either qweb-pdf for PDF reports or qweb-html for HTML.”HTML format” means that the content is displayed as a web page, which is good for browsing an article on screen.A PDF(portable document format) is better for printing because it will preserve the layout that was presented in the print journal, including illustrations. You can also save a PDF to your computer’s hard drive.


The name of our report (which will be the name of the PDF generated)


It is our qweb-template view file. The name of this file should be <module_name>.report_<type_of_report>.


groups allowed to view/use the current report


if set to True, the report will be stored as an attachment of the record using the name generated by the “attachment“ expression; you can use this if you need your report to be generated only once (for legal reasons, for example)


python expression that defines the name of the report; the record is accessible as the variable “object“

Paper format

an external id of the paper format you wish to use

Odoo-Qweb- P1

Step 2 : Define the report template.

For that we have to add template file with the name which is declared in ‘file’ in addition attribute of <report> tag. Therefore here is the name that should be in views/sample_report (No need to add module name here.). We have to add this file in ‘data’ list of file.

<template id=”report_quotation”>

<t t-call=”web.html_container”>

<t t-foreach=”docs” t-as=”o”>

<t t-call=”web.external_layout”>


<h2>Report title</h2>

<p>This object’s name is <span t-field=””/></p>







When we call the external_layout it will take the default header and footer. The contents inside the PDF will reside in the <div>.The template id

must be the same that we defined in the report declared.


Records for the current report


List of ids for the “docs“ records


Model for the docs records


A reference to :mod:`python:time` from the Python standard library


res.user record for the user printing the report


Record for the current user’s company

Translatable Templates

If you wish to translate reports (to the language of a partner, for example), you need to define two templates:

  • The main report template
  • The translatable document

by using the “t-lang” attribute you can call the translatable document from your main template.

1.Main template


<template id=”report_saleorder”>

<t t-call=”web.html_container”>

<t t-foreach=”docs” t-as=”o”>

<t t-call=”sale.report_saleorder_document




  1. Translatable template
<template id=”report_saleorder_document“>

<t t-call=”web.external_layout”>

<t t-set=”o” t-value=”o.with_context({‘lang’:o.partner_id.lang})”/>




<table border=”0″><tr>

<td colspan=”5″>







Inheriting and modifying QWeb reports

Since almost every report in Odoo is a QWeb report. Odoo allows you to inherit existing reports and also to modify anything on the report.

Adding the dependency

Before you can start inheriting QWeb reports you will need to create a new module and configure the correctly. Open up your and also add the dependency for the module where you want to change the report from. However in our example this will be the ‘sale’ module:


‘depends’: [‘sale’],


Without this dependency Odoo would not be able to find the existing report in order to inherit it.

Creating XML file

The next step is to create a new XML file and also to create a new XML record to inherit the existing report. Create a new file with .xml and besides add this new file in your file (under the data key).

Finding the XML ID to inherit

Surely to inherit a report you have to know in which module it is and what the original XML id of the report is. So, how do you find this?The easiest way is to go to Settings > Technical > Reports > Reports and to search the report you want to modify.

Odoo-Qweb- P2
Odoo-Qweb- P3

At the right top you will see a smartbutton named ‘QWeb views’. Click on it. And also this will show you a list of all records that are associated to this specific report.

Odoo-Qweb- P4

So this usually shows you more than one XML record. How do you know which one you need? Because the one that ends with _document is the correct XML record that you need to inherit. Under the column ‘External ID’ you will see there is an unique name, ofcourse although in this example sale.report_saleorder_document. The first part of this text (sale) is the module where the report is from, the second part (report_saleorder_document) is the name of the report that you want to inherit and also modify.

Remember this value (sale.report_saleorder_document) and also open your newly created XML file

Inheriting the existing report

To inherit a QWeb report you’ll need two things: an unique template id and also the inherit_id. The template id can be chosen by yourself, just make sure its unique. In addition the inherit_id should contain the value you’ve just found on your report (sale.report_saleorder_document):

Adding our custom code in the existing report

Let us now add the phone number and also the e-mail address of the customer at the top of the sale order report where the quotation date etcetera are shown. These details are wrapped within a div element that has the class ‘mb32’ set so let us create an xpath expression on this class and let us add our custom code inside of this element:

<xpath expr=”//div[hasclass(‘mb32’)]” position=”inside”>

<div t-if=””>

<strong>Your phone number:</strong>

<p t-field=””></p>


<div t-if=””>

<strong>Your email:</strong>

<p t-field=””></p></div> </xpath>
<xpath expr=”//div[hasclass(‘clearfix’)]” position=”after”>


If there is something wrong then please reach out to your salesperson as soon as possible.



will tell Odoo that we want to add two divs within the div that has the class ‘mb32’. Because If there is a phone filled in on the customer form it’ll be printed on the report. If there is no phone filled in the div will not be used on the report. In addition the same happens for the email. The class ‘col-auto mw-100 mb-2’ will add the two divs behind the existing ones and also will make sure they take up two columns of width on the report.

Finally, let us add a warning at the bottom of the report that if there is something wrong with the customer his quotation that they can reach out to the salesperson:

If you now save your files and also install your custom module again you’ll see the default sale report has been changed