How to Create Custom Header and Footer for External Layout in Odoo18
PDF reports in Odoo allows to create formatted, printable reports that can be customized based on specific requirements of the user these reports are typically used for documents like invoices, quotations, sale orders, purchase orders, delivery slips, and financial statements. Odoo18 comes with new features for customizing the PDF reports to create businesses to create professional, formatted, and fully customized documents like invoices, quotations, sales orders, or financial statements, One of the most commonly customized elements in Odoo reports is the header and footer for external layout . By default, Odoo uses the external_layout_standard template for generating these layouts but developers can easily modify this template to include custom header and footer for external layout with the company’s unique requirements.
In this blog, we will explain how to take over and modify an external_layout_standard template using simple XML there is no complicated coding here and by the end of this blog, you will know how to replace the default header and footer for external layout with your own personalized content, including logos, company details, and other branding elements. so lets get in
Here is a code for the customisation of Odoo default reports which uses the template, External Layout.
To modify the external_layout_standard template in Odoo, create a new template and define the inherit_id to link it to the original layout.
<template id="external_layout_inherited" inherit_id="web.external_layout_standard">
Code For Header Customization
<xpath expr="//div[1]" position="replace">
//your custom header
</xpath>
Example
<odoo>
<template id="external_layout_inherited" inherit_id="web.external_layout_standard">
<xpath expr="//div[1]" position="replace">
<t t-if="company.header_image">
<div t-attf-class="header o_company_#{company.id}_layout">
<img t-att-src="image_data_uri(company.header_image)" alt="Header" style="margin-left: auto;
margin-right: auto; max-width: 100%; height: auto;"/>
</div>
</t>
<t t-else="">
<div t-attf-class="header o_company_#{company.id}_layout">
<div class="d-flex justify-content-between align-items-center mb-2">
<img t-if="company.logo" class="o_company_logo_small" t-attsrc="image_data_uri(company.logo)" alt="Logo"/>
<div t-if="company.report_header" t-field="company.report_header" class="o_company_tagline
mw-50 fw-bold">Company tagline</div>
</div>
<div class="row">
<div class="col-6" name="company_address">
<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-contentcenter 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-contentcenter 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>
</t>
</xpath>
</odoo>
Code For Footer Customisation
<xpath expr="//div[contains(@class, 'footer')]" position="replace">
//your custom footer
</xpath>
Example
<xpath expr="//div[contains(@class, 'footer')]" position="replace">
<t t-if="company.footer_image">
<img t-if="company.footer_image" t-att-src="image_data_uri(company.footer_image)"
alt="Footer" style="margin-left: auto; margin-right: auto; max-width: 100%; height: auto;"/>
</t>
<t t-else="">
<div class="o_footer_content d-flex border-top pt-2">
<div class="flex-grow-1 text-start me-2" t-field="company.report_footer"/>
<div class="text-end text-muted">
<div t-if="report_type == 'pdf' and display_name_in_footer" t-out="o.name">(document
name)</div>
<div t-if="report_type == 'pdf'">Page <span class="page"/> / <span class="topage"/></div>
</div>
</div>
</t>
</xpath>
</template>
Hope it was helpful for the developers.
Customizing headers and footers in Odoo’s PDF reports can significantly enhance the professionalism and branding of your documents by using the simple XML code provided, you can easily replace the default header and footer with your company’s unique details such as logos, taglines, addresses, and even custom footer information like tax IDs or page numbers.
With Odoo18, the flexibility of the report templates means that developers can customize reports to fit business needs without complex coding. this guide provides a solid foundation for modifying your external layout and customizing reports to reflect your brand’s identity.
Custom report headers and footers aren’t just about aesthetics its serve practical functions, such as presenting essential company information, improving document organization, and increasing overall document readability. whether you’re a small business or a large corporation, this customization helps in presenting your reports with a more polished and professional appearance.
If you’re looking for more ways to customize Odoo or need assistance with advanced implementations, don’t hesitate to explore our other Odoo tutorials or contact our team for personalized guidance and support.
"Unlock the Full Potential of Your Business with Odoo ERP!"
"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"
Get a Free Quote