Learn how to customize PDF reports in Odoo 16 directly from the UI. Apply branding, add custom fields, and adjust report layouts with ease.
In Odoo 16, customizing PDF reports from the user interface (UI) lets you adjust report layouts, add branding elements, and personalize the look and feel without needing complex code. This feature allows business users to configure reports directly, making it easier to tailor Odoo reports to match branding needs. In this blog, we’ll guide you through the steps of customizing a report template in Odoo 16 and provide code snippets for more advanced users.
To access report templates for customization in Odoo:
Within the report template, you’ll have access to the HTML structure, allowing you to add or remove fields, apply styling, and include additional elements as needed.
To add fields to your report, such as a company logo or a custom field, you can use the template editor. Below is an example of adding a custom field using the <t>
QWeb directive in the report template:
<t t-name="account.report_invoice_document">
<t t-call="web.external_layout">
<div class="page">
<div class="row">
<div class="col-12 text-center">
<img t-if="o.company_id.logo" t-att-src="'data:image/png;base64,%s' % o.company_id.logo" style="max-width: 200px;" />
<p>Company Logo Added</p>
</div>
</div>
<t t-call="account.report_invoice_header"/>
</div>
</t>
</t>
This code snippet adds the company logo to the top of the PDF invoice report, using QWeb to retrieve the logo
field from the company model.
Odoo allows the use of basic HTML elements and CSS styling to enhance the look and feel of reports. Below is an example of how to create a simple table structure within a report:
<table class="table table-condensed">
<thead>
<tr>
<th>Product</th>
<th>Description</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<t t-foreach="o.invoice_line_ids" t-as="line">
<tr>
<td><t t-esc="line.product_id.name"/></td>
<td><t t-esc="line.name"/></td>
<td><t t-esc="line.price_unit"/></td>
<td><t t-esc="line.price_total"/></td>
</tr>
</t>
</tbody>
</table>
This code generates a table listing products and their details within an invoice report.
To customize headers or footers with color and branding styles, you can add inline styles within the report template:
<div class="header" style="background-color: #3C8DBC; color: white; padding: 10px;">
<h1>Invoice</h1>
</div>
In this example, the header background color is changed to match the company’s primary branding color, making it easier to align reports with corporate design standards.
After making changes, save the template. To see your modifications, go to the relevant record, click Print, and select the report option to generate a PDF preview with your updates.
For advanced users, you can apply further customization using Server Actions to generate specific values or make conditional changes in the report templates:
<record id="action_invoice_custom_report" model="ir.actions.server">
<field name="name">Custom Invoice Report</field>
<field name="model_id" ref="account.model_account_invoice"/>
<field name="state">code</field>
<field name="code">
action = model.browse(record_ids).filtered(lambda r: r.state == 'open').write({'custom_field': True})
</field>
</record>
This server action, for instance, can apply a conditional field update before generating a report, allowing for more dynamic control over what appears on the final PDF.
With Odoo 16, customizing PDF reports directly from the UI is simpler than ever. Using templates, HTML styling, and Odoo’s QWeb, users can configure reports to better reflect business needs without deep coding skills. For more advanced customization, server actions provide further flexibility, ensuring reports are both functional and visually appealing.
Your email address will not be published. Required fields are marked *