How to Modify Header and Footer in Odoo’s QWeb Report (PDF Export)

Odoo’s QWeb Report is a powerful tool for businesses to create custom reports. It is a template-based engine for dynamically creating documents for various purposes. With QWeb Report, businesses can easily generate and deliver highly customized, professional-looking reports in almost any format. It integrates seamlessly with Odoo’s various business applications, allowing businesses to quickly incorporate the most relevant data into reports.

Additionally, QWeb Report is extensible and allows businesses to easily add custom fields and filters, giving them the ability to custom-tailor their reports to their exact business needs. In this article, we will learn to work with the header and footer of the Qweb report.

A PDF report’s header and header contain company and client information like address, and email. We can inherit the view id of the report module for any Odoo before 11, or view id of the web module for Odoo 11+.

The following code is confirmed to be working on Odoo 12.

Added “TTTT” to random position

By default, your report uses standard Document template. Its layout’s id is web.external_layout_standard.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="report_header_footer" inherit_id="web.external_layout_standard">
            <xpath expr="//div[@class='header']" position="replace">
                <div class="header">
                    <div class="row">
                        <div class="col-3 mb4">
                            <img t-if="company.logo" t-att-src="image_data_uri(company.logo)" style="max-height: 45px;"
                                 alt="Logo"/>
                        </div>
                        <div class="col-9 text-right" style="margin-top:22px;" t-field="company.report_header"
                             name="moto"/>
                    </div>
                    <div t-if="company.logo or company.report_header" class="row zero_min_height">
                        <div class="col-12">
                            <div style="border-bottom: 1px solid black;"/>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-6" name="company_address">
                            <div t-field="company.partner_id"
                                 t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'
                            />
                        </div>
                    </div>
                </div>
            </xpath>
            
            <xpath expr="//div[@class='footer o_standard_footer']" position="replace">
                <div class="footer o_standard_footer">
                    <div class="text-center" style="border-top: 1px solid black;">
                        <ul class="list-inline mb4">
                            <li t-if="company.phone" class="list-inline-item">Phone:
                                <span t-field="company.phone"/>
                            </li>
                            <li t-if="company.email" class="list-inline-item">Email:
                                <span t-field="company.email"/>
                            </li>
                            <li t-if="company.website" class="list-inline-item">Web:
                                <span t-field="company.website"/>
                            </li>
                            <li t-if="company.vat" class="list-inline-item"><t
                                    t-esc="company.country_id.vat_label or 'Tax ID'"/>:
                                <span t-field="company.vat"/>
                            </li>
                        </ul>

                        <div name="financial_infos">
                            <span t-field="company.report_footer"/>
                        </div>

                        <div t-if="report_type == 'pdf'" class="text-muted">
                            Page:
                            <span class="page"/>
                            /
                            <span class="topage"/>
                        </div>
                    </div>
                </div>
            </xpath>
        </template>
    </data>
</openerp>

For other document templates, you can check report_templates.xml file in the web module.

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close