Skip to main content

Create a Custom QWeb Report in Odoo

Do you need to generate custom reports for your business, but find the standard Odoo reporting functions are not enough? Don’t worry, with a little bit of Python programming you can create custom QWeb reports that will meet your exact needs. In this tutorial, we will show you how to create a report with required elements.

<?xml version="1.0" encoding="utf-8"?>

    <!-- Invoice templates -->
    <template id="custom_invoice_custom_report">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="doc">
                <t t-call="my_module.custom_invoice_external_layout">
                    <div class="page" style="font-family: sans-serif; font-size: 15px;">
                        <div t-if="">
                            Invoice No.: <span t-field=""/>
                        <div t-if="">
                            Partner: <span t-field=""/>
                        <!-- Invoice lines -->
                        <t t-foreach="doc.invoice_line_ids" t-as="line">


    <!-- Layout -->

    <template id="custom_invoice_external_layout_standard">
        <!-- Header -->
        <div t-attf-class="header o_company_#{}_layout">
            <div class="row" style="align-items: center;">
                <img t-if="company.report_header_custom" t-att-src="image_data_uri(company.report_header_custom)" alt="Logo" style="max-height: 269px;"/>
        <!-- Footer -->
        <div class="footer">
            <div class="text-center">
                Page: <span class="page"/> of <span class="topage"/>

        <div t-attf-class="article o_company_#{}_layout"
             t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and"
             t-att-data-oe-lang="o and o.env.context.get('lang')">
            <t t-call="web.address_layout"/>
            <t t-raw="0"/>


    <!-- Public api: layout to t-call from reports -->
    <template id="custom_invoice_external_layout">
        <t t-if="not o" t-set="o" t-value="doc"/>
        <t t-if="not company">
            <!-- Multicompany -->
            <t t-if="company_id">
                <t t-set="company" t-value="company_id"/>
            <t t-elif="o and 'company_id' in o">
                <t t-set="company" t-value="o.company_id.sudo()"/>
            <t t-else="else">
                <t t-set="company" t-value="res_company"/>

        <t t-call="my_module.custom_invoice_external_layout_standard">
            <t t-raw="0"/>


    <!-- Custom Invoice Report Action -->
            string="Custom Invoice Report"
            print_report_name="(object.number or 'Custom Invoice Report')"
    <record id="paperformat_invoice_report" model="report.paperformat">
        <field name="name">Custom Invoice Report Paperformat</field>
        <field name="default" eval="True"/>
        <field name="format">A4</field>
        <field name="orientation">Portrait</field>
        <field name="margin_top">35</field>
        <field name="margin_bottom">15</field>
        <field name="margin_left">5</field>
        <field name="margin_right">5</field>
        <field name="header_line" eval="False"/>
        <field name="header_spacing">30</field>
        <field name="dpi">90</field>
    <record id="my_module.custom_invoice_report_action" model="">
        <field name="paperformat_id" ref="my_module.paperformat_invoice_report"/>

By continuing to use the site, you agree to the use of cookies.