Create report


Create report#

A frequent requirement is to generate a printable document for a record. For that we use which provides the tooling to render OpenDocument based on relatorio template.

First we create a class in

from import Report
class OpportunityReport(Report):
    __name__ = ''

And we register it in the Pool as type report in

def register():
        module='opportunity', type_='report')

Now we have to create a and ir.action.keyword in opportunity.xml:

      <record model="" id="report_opportunity">
         <field name="name">Opportunity</field>
         <field name="report_name"></field>
         <field name="model">training.opportunity</field>
         <field name="report">opportunity/opportunity.fodt</field>
         <field name="template_extension">odt</field>
      <record model="ir.action.keyword" id="report_opportunity_keyword">
         <field name="keyword">form_print</field>
         <field name="model">training.opportunity,-1</field>
         <field name="action" ref="report_opportunity"/>

The links the with the Model.


The string that is shown on the menu.


The name of the


The name of the Model.


The path to the template file starting with the module directory.


The template format.

And like for the wizard, the ir.action.keyword makes the available as action to any training.opportunity.

Finally we create the OpenDocument template as opportunity.fodt using LibreOffice. We use the Genshi XML Template Language implemented by relatorio using Placeholder Text. The rendering context contains the variable records which is a list of selected record instances.

Here is an example of the directives to insert in the document:

<for each="opportunity in records">
Opportunity: <opportunity.rec_name>
Party: <>
Start Date: <format_date(opportunity.start_date) if opportunity.start_date else ''>
End Date: <format_date(opportunity.end_date) if opportunity.end_date else ''>

<for each="line in (opportunity.comment or '').splitlines()">


We must render text field line by line because OpenDocument does not consider simple breakline.

Update database#

As we have registered new report and XML records, we need to update the database with:

$ trytond-admin -d test --all

And restart the server and reconnect with the client to test rendering the report:

$ trytond

Next we create a a reporting model using SQL query.