jinja_reports is a jinja2 extension developed to work with Tryton ERP. We can create our own reports based on jinja2 with html templates.
Steps to use Jinja Reports:
- Inherit the base Jinja2Report class.
- Define the meta model name.
- Create an html template.
- Create an action report pointing to template path and model name.
Here's a an example of a report which contains three files.
- Python class that must be registered to the Tryton Pool.
from trytond.modules.jinja_report.report import Jinja2Report
from trytond.pool import Pool
class MyReport(Jinja2Report):
__name__ = 'my_module.my_report'
def register():
Pool.register(MyReport, module='your_module', type_='report')
- The html template of your report
<html>
<body>
{% for record in records %}
{{ record.name }}
{% endfor %}
{{ data.get('some_data') }}
</body>
</html>
- The action report registered as xml:
<record model="ir.action.report" id="my_report_action">
<field name="name">Title of my report</field>
<field name="report">path/to/my/report.html</field>
<field name="report_name">my_module.my_report</field>
<field name="model">party.party</field>
<field name="extension">pdf</field>
<field name="template_extension">html</field>
</record>