In this article I am going to teach you how to add custom header and footer in QWEB reports in odoo. You guys already know that how to customize the default Odoo header and footer in QWEB reports by changing the company setting.
Sometime you want to customize report header and footer according to your desire instead of showing company information, to do that we need to edit the QWEB view. Here we will inherit/override existing template (xml) like report layout (report.external_layout_header and report.external_layout_footer) instead of directly changing in source code.
Read More: How to Create QWEB Report in Odoo
Inherit or Override QWEB report header and footer
To customize report header and footer we need inherit/override these two report templates.
- report.external_layout_header
- report.external_layout_footer
You just need to inherit or override above templates and simply apply bootstrap or CSS classes for your header and footer on your custom template according to your need and requirement.
Follow these steps to override report layouts.
- Create a new XML file and name it (custom_header.xml)
- Create a new XML file and name it (custom_footer.xml)
- Add this file into __manifest__.py or (__openerp__.py) file
add_custom_header_in_qweb_report.xml
In below code we have inherited or override "external_layout_header" template. And customize that template according to our need using Bootstrap and CSS.
add_custom_footer_in_qweb_report.xml
In below code we have inherited or override "external_layout_footer" template. And customize that template according to our need using Bootstrap and CSS.
Now we can use that template in our Odoo QWEB reports to display our customize header and footer.
In above code we have used "report.html_container" that's why we explicitly use "report.external_layout_header" and "report.external_layout_footer". If we will use "report.external_layout" than there is no need to call header and footer template.
3 Comments
There are differences between odoo v8 and v11. For example you shouldn't use report.html_container in odoo 11, you have to use web.html_container.
ReplyDeleteYes, you are right :)
DeleteHello do you know how to get API odoo v11? Thankyou
ReplyDelete