Search Here

How to Add Custom Header and Footer in QWEB Reports

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. 



How to add custom header and footer in QWEB reports in odoo

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.

Inherit or Override QWEB report header and footer


To customize report header and footer we need inherit/override these two report templates.

  1. report.external_layout_header  
  2. 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.

  1. Create a new XML file and name it (custom_header.xml)
  2. Create a new XML file and name it (custom_footer.xml)
  3. 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.



How to add custom header and footer in QWEB reports in odoo

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.

Post a Comment

3 Comments

  1. 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.

    ReplyDelete
  2. Hello do you know how to get API odoo v11? Thankyou

    ReplyDelete