Odoo 17 ERP: Adding Custom Header/Footer To All Reports

Odoo 17 ERP: Adding Custom Header/Footer To All Reports

Divya Vaishanav

11 Jun 2024

4 MINUTES READ

Table of Contents

Introduction

Reports are essential papers that provide information sharing and in-depth data analysis in the business domain. Businesses have access to a wide range of report kinds within the Odoo platform, such as purchase, sale, and invoicing reports. Predefined report layouts like "external_layout_standard," "external_layout_striped," and "external_layout_bold," all painstakingly created using HTML/QWeb, are another way that Odoo further improves versatility. Users can customize the header and footer elements by creating a new layout or by inheriting and changing an existing one, allowing reports to be tailored to individual needs. This adaptability enables companies to display content in a way that perfectly suits their own needs and tastes.

  1. Turn on Odoo's debug mode.
  2. Go to the Document Layout Configuration configuration configuration settings and select your favorite layout, like "external_layout_standard.
  3. Select "Edit Layout" to open the report template and make changes.
  4. To create a new view that derives from the current layout, use the "Inherit View" option.
Personalize the Footer and Header
  1. Customize the header and footer elements to meet your needs.
Save and Execute Modifications:
  1. Save the changes and incorporate them into the report.

Through the use of inheritance from the current layout, you can easily modify a report's header and footer sections to suit your unique requirements.

report

Take inherit_id from external_layout_standard template and define it in the template to personalize the report.

    
    <template inherit_id="module_name.layout name" id=""></code-display>
    

Once you have inherited the template, apply the necessary modifications.

        
    <?xml version="1.0" encoding="UTF-8"?>
    <odoo>
    <template id="custom_standard_external_layout"
                inherit_id="web.external_layout_standard">
        <xpath expr="//div[1]" position="replace">
            <div t-attf-class="header o_company_#{company.id}_layout"
                    t-att-style="report_header_style">
                <div class="row mb8">
                    <div class="col-12">
                        <div class="d-flex justify-content-end">
                            <img t-if="company.logo"
                                    t-att-src="image_data_uri(company.logo)"
                                        style="max-height:40px;max-width:140%"
                                    alt="Logo"/>
                        </div>
                        <div class="col-9 text-end"
                                style="margin-top:22px;"
                                t-if="company.report_header"
                                t-field="company.report_header"
                                name="moto">Company tagline
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-12" name="company_address">
                        <div class="d-flex justify-content-end" 
                                style="text-align: right;">
                            <ul class="list-unstyled" name="company_address_list">
                                <li t-if="company.is_company_details_empty">
                                    <span t-field="company.partner_id" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'>
                                    <div class="bg-light border-1 rounded h-100 d-flex flex-column align-items-center justify-content-center p-4 w-100 opacity-75 text-muted text-center">
                                        <strong>Company address block</strong>
                                        <div>Contains the company address.</div>
                                    </div>
                                </span></li>
                                <li t-else="">
                                    <span t-field="company.company_details">
                                        <div class="bg-light border-1 rounded h-100 d-flex flex-column align-items-center justify-content-center p-4 w-100 opacity-75 text-muted text-center">
                                            <strong>Company details block</strong>
                                            <div>Contains the company details.</div>
                                        </div>
                                    </span>
                                </li>
                                <li t-if="not forced_vat"/>
                                <li t-else="">
                                    <t t-esc="company.country_id.vat_label or 'Tax ID'">Tax ID</t>:
                                    <span t-esc="forced_vat">US12345671</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </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>
            </xpath>
        <xpath expr="//div[@t-attf-class='footer o_standard_footer o_company_#{company.id}_layout']" position="replace">
            <div t-attf-class="footer o_standard_footer o_company_#{company.id}_layout">
                <div class="text-center" style="border-top: 1px solid black;">
                    <h5 style="color:black;">
                        <b><t t-esc="company.name"/></b>
                    </h5>
                    <h6 style="color:black;">Your company details</h6>
                    Page:
                    <span class="page"/>/<span class="topage"/>
                </div>
            </div>
        </xpath>
    </template>
    </odoo>
    

XML code and XPath expressions can be used to customize the report header and footer after inheriting the template. We can utilize positional values like "replace", "after", or "before" based on our own customization needs.

For example, we can use the following XPath query to replace the first element in 'external_layout_striped' that typically holds the header:

        
    <xpath expr="//div[1]" position="replace">
    </xpath>
    

You may use <span> elements with the "page" and "topage" classes to display page numbers in the footer:

You can use these range classes in the header and footer parts of your PDF report to offer page number information.

You can use variables like 'o' or 'docs' to retrieve data from the corresponding model, and you can use dotted paths like 'o.partner_id.name' to fetch specific values from other models. Are these values printable? Applying the "t-field" or "t-esc" properties to <span> elements:

        
    <span t-esc="o"/>
    

You can include more layouts in your inherited layout by using the "t-call" directive, which will prevent you from copying the same layout's design:

        
    <tcall="module_name.layout_name"/>
    

A page number appears in the footer and a logo appears in the header of the typical "external_layout_striped" header and footer. In place of that, a purchase order is printed in the example.

Remember that the supplied XML snippets are placeholders; the real modification code must be used in their place.

Below are the sales order report's header and footer without any change.

header and footer

Following customization, the text appears below.

header and footer2

Conclusion

Customizing headers and footers in Odoo 17 ERP reports is a straightforward process with XML and XPath expressions. By inheriting templates and making targeted modifications, businesses can tailor their reports to suit their unique requirements, enhancing brand consistency and information presentation.

FAQ

The answer is yes, you may follow these easy steps to change headers and footers in Odoo 17 reports. To choose your favorite layout, first activate Odoo's debug mode and then go to the Document Layout Configuration options. Once the layout has been chosen, you can adjust it to modify the header and footer sections to suit your needs.

It is possible to include your company's logo in the report heading. You can add an image tag referring your company's logo file to the header element's customisation settings. Just make sure it's the right size and location for your report layout.

In order to customize reports, the following XPath expressions are frequently used: expr="//element": Chooses every element that has the given tag name. position="replace": Inserts the custom content in place of the selected element. position="before" or="after": Places the custom content in front of or behind the chosen element, depending on which is selected.

In your footer customisation, you can include elements with classes like "page" and "topage" to display page numbers in the report footer. The current page number and the total number of pages in the report are automatically displayed by these classes.

Divya Vaishanav
Divya Vaishanav

Marketing Executive

Divya Vaishnav is a dynamic Marketing Executive known for her innovative strategies and keen market insights. With a talent for crafting compelling campaigns, she drives brand growth and customer engagement.

Linkedin
Hire Skilled Developer

*Please fill all the required fields

Get our Newsletter

Customized solutions for your projects

*Please fill all the required fields