Enable Dark Mode!
how-to-customize-headers-and-footers-for-all-reports-in-odoo-19.jpg
By: Sonu S

How to Customize Headers and Footers for All Reports in Odoo 19

Technical Odoo 19 Reporting

Odoo 19 is the latest version of the open-source business management suite, bringing improved usability, performance, and flexibility across its modules. One of its key strengths carried forward and enhanced from Odoo 19 is its reporting framework, which helps businesses generate clear, insightful, and customizable reports. Reports are central to informed decision-making and efficient communication within an organization. Odoo provides a diverse set of report types including sales orders, purchase reports, and customer invoices to serve various operational needs. To support different presentation styles, Odoo 19 continues to offer a range of predefined layouts such as external_layout_standard, external_layout_striped, and external_layout_bold, external_layout_bubble etc, all created using the versatile QWeb templating engine.

For companies seeking greater control over report appearance, Odoo makes it easy to customize headers and footers by either building new layouts or extending existing ones through inheritance. This flexibility allows organizations to align their reports with specific branding, design, and content requirements, making Odoo 19’s reporting system both highly customizable and business-ready.

Steps to Customize Report Layouts in Odoo 19:

  1. Enable Developer Mode: Begin by turning on debug (developer) mode in your Odoo 19 instance. This allows you to access technical settings and tools needed for advanced report customization.
  2. Access Layout Settings: Navigate to the Document Layout section under Configuration > Settings. Click Edit Layout and choose your preferred report layout, such as external_layout_standard, to define the base style for your reports.
  3. Edit the Layout: Click the “Edit Layout” button to open the base template of the selected report layout. This lets you view and modify the default structure, including elements like headers, footers, and company details.
  4. Create an Inherited View: Use the “Inherit View” option to create a new view that extends the selected layout template. This method allows you to apply customizations without altering the original file, ensuring your changes remain clean, maintainable, and safe during future Odoo upgrades.
  5. Customize Header and Footer: Adjust the header and footer sections to fit your branding needs. You can add elements such as your company logo, address, contact information, or other brand-specific details to give your reports a professional and personalized look.
  6. Save and Apply: After completing your customizations, save the inherited view and link it to the relevant reports. This ensures your updated layout is applied whenever those reports are generated.

How to Customize Headers and Footers for All Reports in Odoo 19-cybrosys

By using Odoo’s inheritance system, you can modify existing report layouts to align with your company’s branding and reporting requirements without altering the original templates. This approach keeps your customizations upgrade-safe and easy to maintain.

To customize a report in Odoo, you create a new template that inherits the external_layout_standard template using the inherit_id attribute. For example:

<template inherit_id="web.external_layout_standard" id="your_custom_layout_id">
            <!-- Add your changes here -->
        </template>

Once you have inherited the template, you can make specific changes to customize your report. For example:

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- Custom Header & Footer: Inherited from the standard external layout -->
    <template id="custom_standard_layout" inherit_id="web.external_layout_standard">
        <!-- Customize the Header -->
        <xpath expr="//div[contains(@t-attf-class, 'header o_company_')]" position="replace">
            <div t-attf-class="header o_company_#{company.id}_layout" style="padding: 15px 10px;">
                <div class="d-flex justify-content-start align-items-center mb-3">
                    <!-- Company Logo -->
                    <img t-if="company.logo" class="o_company_logo_small me-3" t-att-src="image_data_uri(company.logo)"
                         alt="Company Logo"/>
                    <!-- Company Details -->
                    <div class="company-details">
                        <!-- Company Name -->
                        <t t-if="company.name">
                            <h2 class="company-name" style="font-weight: bold; margin:0 0 5px 0;">
                                <t t-esc="company.name"/>
                            </h2>
                        </t>
                        <!-- Company Address -->
                        <t t-if="company.partner_id.street or company.partner_id.city or company.partner_id.zip">
                            <p style="margin: 0; font-size: 12px;">
                                <strong>Address:</strong>
                                <t t-esc="company.partner_id.street or ''"/>
                                <t t-if="company.partner_id.city">, <t t-esc="company.partner_id.city"/></t>
                                <t t-if="company.partner_id.zip">, <t t-esc="company.partner_id.zip"/></t>
                            </p>
                        </t>
                        <!-- Company Contact Info -->
                        <t t-if="company.partner_id.phone or company.partner_id.email or company.website">
                            <p style="margin: 0; font-size: 12px;">
                                <t t-if="company.partner_id.phone">Phone: <t t-esc="company.partner_id.phone"/> </t>
                                <t t-if="company.partner_id.email">Email: <t t-esc="company.partner_id.email"/> </t>
                                <t t-if="company.website">Website: <t t-esc="company.website"/> </t>
                            </p>
                        </t>
                    </div>
                </div>
                <!-- Divider -->
                <div style="border-bottom: 1px solid #bbb; margin-top: 10px;"></div>
            </div>
        </xpath>
        <!-- Customize the Footer -->
        <xpath expr="//div[contains(@class, 'o_footer')]" position="replace">
            <div class="custom_footer text-center" style="border-top: 1px solid #333; padding: 10px 0; font-size: 11px;">
                <!-- Company Name and Page Number -->
                <div class="row mb-1">
                    <div class="col-6 text-start">
                        <strong><t t-esc="company.name"/></strong>
                    </div>
                    <div class="col-6 text-end">
                        Page: <span class="page"/> / <span class="topage"/>
                    </div>
                </div>
                <!-- Company Address -->
                <div class="row">
                    <div class="col-12 text-center">
                        <p style="margin:0;">
                            <t t-esc="company.partner_id.street or ''"/>
                            <t t-if="company.partner_id.city">, <t t-esc="company.partner_id.city"/></t>
                            <t t-if="company.partner_id.country_id">, <t t-esc="company.partner_id.country_id.name"/></t>
                        </p>
                    </div>
                </div>
            </div>
        </xpath>
    </template>
</odoo>

After inheriting the template, you can customize the report’s header and footer by writing XML code and using XPath expressions to target specific elements. Depending on your requirements, you can use positional attributes like replace, after, or before to control how your changes are applied within the existing layout.

In this example, the web.external_layout_standard template is inherited to customize the report’s header and footer. XPath expressions are used to pinpoint the sections that need modification. The header section can be targeted with an expression like:

<xpath expr="//div[contains(@t-attf-class, 'header o_company_')]" position="replace">

The footer section can be targeted using an XPath expression like this:

<xpath expr="//div[contains(@class, 'o_footer')]" position="replace">

By using position="replace", the original content is completely substituted with your custom layout. Typically, the customized header can include the company logo, name, address, and contact information in a clear, professional format. The footer can display the company name, page numbers, and address details, providing a consistent and branded appearance across all reports. This approach preserves the underlying template structure while allowing flexible personalization.

To pull data from the relevant model, you can use variables such as o or docs. You can also access related fields using dotted notation—for example, o.partner_id.name to get the partner’s name. These values can then be inserted into the report using QWeb tags like <span t-field="o.partner_id.name"/> or <span t-esc="o.partner_id.name"/>.

<span t-esc="o.partner_id.name"/>

To prevent duplicating layout structures, the t-call directive can be used to include existing templates within your inherited layout.

<t-call="module_name.layout_name"/>

Here is an example of the default header and footer for the Sales Order report in Odoo, before any customizations:

How to Customize Headers and Footers for All Reports in Odoo 19-cybrosys

Here is an example of a customized Sales Order report with an updated header and footer:

How to Customize Headers and Footers for All Reports in Odoo 19-cybrosys

In Odoo 19, report headers and footers can be customized by inheriting the default layout template and using XPath expressions to target specific sections for modification. This approach allows businesses to personalize reports while preserving a consistent and professional structure across all documents. By replacing the standard header and footer with custom elements such as logos, contact details, and branded styling organizations can enhance both the visual appeal and the corporate identity of their reports.

To read more about How to Customize Header/Footer for All Reports in Odoo 18, refer to our blog How to Customize Header/Footer for All Reports in Odoo 18


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message