Enable Dark Mode!
By: Yadukrishna K

How to Create a Pdf Report in Odoo 13

Technical Odoo 13

A report is a document that can present information about a company or organization in an organized format for a specific audience and purpose. Reports play a significant role in the growth of the business. Odoo uses two types of report types are qweb-pdf and qweb-html. The easiest and useful report is qweb-pdf. So odoo uses qweb in more cases to access data from models and get a perfect view for the report.
Here we use the qweb-pdf report type for this operation. So I created a button and created a function with the button name.
In python file( module_name > models > .py )

def button_name(self):
data = {
'model_id': self.id,
return self.env.ref(module_name.print_report_pdf').report_action(self, data=data)
Here I am using a code to trigger an XML part so I specified the model name and id of the XML part.
After this code creates a directory named as report inside the module and creates an xml file.
Then write this snippet on the XML file. The id of this report tag must be equal to the reference that we specified earlier in the python part, not the name of the XML file.

In xml part (module_name > report > .xml)
<report id="print_report_pdf'"
string="Sample Report"
After this xml part creates a python file inside the report directory.(eg:- module_name > report > .py)

You must be bothered about specifying the name of the model. In the above XML part, one can see an attribute name. You should use the string to create a model name by adding a report before this string.

In python file
class SampleReportPrint(models.AbstractModel):
    _name = 'report.module_name.print_sample_report'
    def _get_report_values(self, docids, data):
        """in this function can access the data returned from the button
        click function"""
        model_id = data['model_id']
        value = []
        query = """SELECT *
                        FROM sale_order as so
                        JOIN sale_order_line AS sl ON so.id = sl.sale_order_id
                        WHERE sl.id = %s"""
        self._cr.execute(query, value)
        record = self._cr.dictfetchall()
        return {
            'docs': record,
            'date_today': fields.Datetime.now(),
After writing the python code I have to create a template for the print report.
To create an XML file for the report template. This template helps to get data from the report model and also can align content like HTML.
In report template part ( module_name > report > .XML )
<?xml version="1.0" encoding="UTF-8"?>
        <template id="print_sample_report">
            <t t-call="web.html_container">
                <t t-call="web.external_layout">
                    <div class="page">
                        <h1 align="center">
                            Sample Report
                        <t t-forech="docs" t-as="line">
                                <t t-esc="line['name']"/>
                                <t t-esc="date_today"/>
In this template, I used a loop for getting values from the variable docs.
You must check all the files paths added to the manifest file and update odoo then install your module.

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



Hi @Yadukrishna, I have an error Traceback (most recent call last): File "/home/maicoly/boxbeep/pyrhonoddo/odoo13-boxbeep/addons/web/controllers/main.py", line 2032, in report_download response = self.report_routes(reportname, converter=converter, context=context, **data) File "/home/maicoly/boxbeep/pyrhonoddo/odoo13-boxbeep/odoo/http.py", line 515, in response_wrap response = f(*args, **kw) File "/home/maicoly/boxbeep/pyrhonoddo/odoo13-boxbeep/addons/web/controllers/main.py", line 1963, in report_routes pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0] File "/home/maicoly/boxbeep/pyrhonoddo/odoo13-boxbeep/odoo/addons/base/models/ir_actions_report.py", line 741, in render_qweb_pdf if self.attachment and set(res_ids) != set(html_ids): TypeError: 'NoneType' object is not iterable please help me!





I have a Qweb report in "res.partner" I need to call this report based on related field (partner_id) from "account.invoice" Please help to get python function for this requirement..




Leave a comment




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



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



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

Send Us A Message