Sei sulla pagina 1di 7

12/31/2018 Inheriting and modifying QWeb reports - Odoo tutorials

 

Inheriting and
modifying QWeb
reports
 OCTOBER 3, 2015  YENTHE666
http://www.odoo.yenthevg.com/inheriting-and-modifying-qweb-reports/ 7/22
12/31/2018 Inheriting and modifying QWeb reports - Odoo tutorials

Hi guys,

In this tutorial you will learn how to inherit already


existing QWeb reports in a custom module. After this
tutorial you will be able to inherit and modify any
already existing QWeb report in Odoo!
In this example I will modify the default Quotation /
order report through inheritance and I will remove a
few elements from the report.

1. Creating a new module

The rst step is to create a new module. The correct


behaviour in Odoo is to always inherit, don’t ever
modify existing les. Start by creating yourself a new
module.
Tip: use the sca old command from Odoo!

This will create a new module from scratch and the


default structure of your module is already there.

 2. Creating your XML file

The next step is to open up your XML le (in my



example templates.xml) and to create a new record to
inherit the report. 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 nd this?
The easiest way is to go to ‘Settings’ > ‘Reports’ >
‘Reports’ and to search the report you want to modify.
In this tutorial this will be the quotation/order report
so I’ll search for ‘Order’:

http://www.odoo.yenthevg.com/inheriting-and-modifying-qweb-reports/ 8/22
12/31/2018 Inheriting and modifying QWeb reports - Odoo tutorials

Now that you’ve found your report click on it. This will
open a new view where you will nd all the technical
information you need! For example with the quotation
report:

 

At the right you will see a clickable link named ‘Search


associated QWeb views’. Click on it. This will show you
a list of all records that are associated to this speci c
report. In the example of the quotation report:

So this usually shows you two XML records. How do


you know which one you need? The one that ends
with _document is the correct XML record that you
need to inherit. Under the column ‘External ID’ you will

http://www.odoo.yenthevg.com/inheriting-and-modifying-qweb-reports/ 9/22
12/31/2018 Inheriting and modifying QWeb reports - Odoo tutorials

see there is an unique name, in this example


sale.report_saleorder_document. The rst 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 modify.

Remember this value and now open up your XML le.


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

1 <!-- Inherit quotation report (from


from module s
2 <template id="report_quotation_inherit_demo"
3 </template>

That is it! You’re now already on the correct report and


are inheriting it. So, how do you now add or remove
elements? To do this you will need Xpath expressions
to nd, modify, replace or add elements. Tip: Don’t
know how Xpath expressions work? Follow my tutorial

 here!
For this example I will remove the columns that show

the amount, the tax and the price per item. The rst
step is to modify the table header:

1 <!-- Finds the first table with as class tab


2 This will replace everything withing tr (inc
3 <xpath expr="//table[@class='table table-con
4     <tr style="background-color:lightgray;">
5         <th>Description</th>
6         <th class="text-right">Price</th>
7     </tr>
8 </xpath>

After modifying the table header the table content


should also be modi ed.

1 <xpath expr="//tbody[@class='sale_tbody']//t
2 </xpath>
3 <xpath expr="//tbody[@class='sale_tbody']//t
4 </xpath>
http://www.odoo.yenthevg.com/inheriting-and-modifying-qweb-reports/ 10/22
12/31/2018 Inheriting and modifying QWeb reports - Odoo tutorials

5 <xpath expr="//tbody[@class='sale_tbody']//t
6 </xpath>

This code will remove the fourth, third and second td


element and all its content but only for the tbody with
class ‘sale_tbody’ and inside the tr.
So this will replace the header and the table content
from this report. Have a look at the full code to inherit
and modify your QWeb report:

1 <openerp>
2     <data>
3         <!-- Inherit quotation report (from
from
4         <template id="report_quotation_inhe
5     <!-- Finds the first table with as
6 This will replace everything withi
7     <xpath expr="//table[@class='table
8                     <tr style="background-c
9                         <th>Description</th
10                         <th class="text-rig
11                     </tr>
12     </xpath>
13     <xpath expr="//tbody[@class='sale_t
14     </xpath>
15     <xpath expr="//tbody[@class='sale_t

 16
17
18
    </xpath>
    <xpath expr="//tbody[@class='sale_t
    </xpath>

19         </template>
20     </data>
21 </openerp>

If you would now print out the report you would get
this as a result:

http://www.odoo.yenthevg.com/inheriting-and-modifying-qweb-reports/ 11/22
12/31/2018 Inheriting and modifying QWeb reports - Odoo tutorials

3. Adding the dependency for the


external QWeb report

The next, and nal step, is to add a dependency.


Because this QWeb report is inside another module
Odoo has to know about this module and its content
so you should add a dependency. Without this your
module will not work and you will get errors.
Open up your __openerp__.py le in your custom
module and nd the line with depends.

 Now take back that ‘External ID’ from the QWeb report
and take the rst part of the external id (before the

dot). This tells you which module you should add as a
dependency:

In this example my QWeb comes from the sale


module, so I will add it as a dependency.

1 # any module necessary for this one to work


2 'depends': ['sale'],

4. Conclusion

Thats it! You’re done with inheriting and modifying the


QWeb report. When you now install this module in
http://www.odoo.yenthevg.com/inheriting-and-modifying-qweb-reports/ 12/22
12/31/2018 Inheriting and modifying QWeb reports - Odoo tutorials

your Odoo you will see the modi ed report.


Do you want to try a demo module and see the
source code of this tutorial? You can view on my
Github account.
Has this tutorial helped you, do you have any feedback
or questions? Post away!

Share this:

 Share

Like this:

Like

 Be the first to like this.



INHERIT_ID QWEB

17 thoughts on “Inheriting and modifying QWeb


reports”

Laura

Hi!

http://www.odoo.yenthevg.com/inheriting-and-modifying-qweb-reports/ 13/22

Potrebbero piacerti anche