How to Customize PDF Reports from the User Interface in Odoo

Abid Patel
26-Oct-2024 Updated : 26-Oct-2024

Learn how to customize PDF reports in Odoo 16 directly from the UI. Apply branding, add custom fields, and adjust report layouts with ease.

How to Customize PDF Reports from the User Interface in Odoo

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.

Accessing the PDF Report Template in Odoo 16

To access report templates for customization in Odoo:

  • ▹ Open the Settings app.
  • ▹ Navigate to Technical > Reports > Templates.
  • ▹ Select the specific report template you want to customize, such as Invoices or Sales Orders.

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.

Adding Custom Fields to a Report Template

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:

xml
<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.

Adjusting Layout with Styling and Table Structure

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:

xml
<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.

Applying Dynamic Branding to PDF Reports

To customize headers or footers with color and branding styles, you can add inline styles within the report template:

xml
<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.

Saving and Previewing the Customized Report

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.

Advanced Customization with Server Actions

For advanced users, you can apply further customization using Server Actions to generate specific values or make conditional changes in the report templates:

xml
<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.

Conclusion

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.

Make a Comment

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