Skip to main content

Tryton Webkit Report

Project description

Webkit based PDF report engine

.. image::

This package allows you to build HTML based reports and then convert them
into PDFs using either `wkhtmltopdf` which uses the webkit rendering engine and
QT. (WebKit is the engine of Apples Safari). or
`Weasyprint <http://>`_

The templates are written using `Jinja 2 <>`_
template engine. `Template Inheritance
<>`_ is also
supported to make it easier to extend existing emails and having a single
theme for all your emails.

The package also supports Genshi Template
`Inheritance <>`_.

Using this in your projects

Instead of using the default report class from use the
ReportWebkit class from this package instead.

.. code-block:: python

from openlabs_report_webkit import ReportWebkit

class UserReport(ReportWebkit):
__name__ = 'res.user'

def get_jinja_filters(cls, *args, **kwargs):
Add my custom filters
filters = super(UserReport, cls).get_jinja_filters(*args, **kwargs)
'nl2br': lambda value: value.replace('\n','<br>\n')
return filters

Output Formats

To get PDF outputs (instead of standard html) ensure that the report
definition in xml clearly shows the extension as PDF. This could be
changed from the tryton administration section too.

To convert to PDFs this module needs either the ``wkhtmltopdf`` or
``weasyprint`` installed.

Installing wkhtmltopdf (default)

Installing wkhtmltopdf from debian repositories usually install an older
version which does not have support for features like page numbers at the
end of each page. So remember to install the latest one published by the
maintainers. For details refer to
`wkhtmltopdf project website <>`_.

Installing weasyprint

Weasyprint is a much lighter option (in comparison to wkhtmltopdf) but
with lesser features. Weasyprint can be installed from PYPI.

``pip install weasyprint``

To use weasyprint, your report implementation class must explicitly
override the convert api to use weasyprint. Example:

.. code-block:: python

# TODO: an example here

Template Filters

Tryton HTML reports arrive with some builtin Template filters (in addition
to the `built-in filters of Jinja2
<>`_) to make
things easier:

dateformat(date, format='medium')

Format the date with the current language from the context. For other
possible formats, refer the
`babel documentation <>`_.


.. code-block:: html+jinja

<td>{{|dateformat }}</td>

datetimeformat(datetime, format)

Format the datetime with the current language from the context. For other
possible formats, refer the
`babel documentation <>`_.


.. code-block:: html+jinja

<td>Created on {{ sale.create_date|datetimeformat('long') }}</td>

currencyformat(amount, currency, format=None)

Return formatted currency value. For more formatting information refer
`babel documentation <>`_


.. code-block:: html+jinja

<td>Total Value</td>
<td>{{ sale.total_amount|currencyformat(sale.currency.code) }}</td>


Get the absolute Path of a file within a module


.. code-block:: html+jinja

<img src="{{ 'company/logo.png'|modulepath }}"/>

Of course you can add your own as stated above.

Including Styles

To include stylesheets, images or any other static data you have two options:

1. Have Tryton serving your files by adding the static-directory to your
Tryton json_path
2. Bundle your static files inside the reports module and reference using

.. code-block:: html+jinja

<link rel="stylesheet" href="{{ 'reports/main.css' | module_path }}" type="text/css">

The second approach comes with the downside that static files will only be
available on the server, so you can only see the formatted pdf

Adding as a dependency

You can add the report toolkit as a dependent package of your tryton
module by adding into the install_requires list on your script.
Remember to specify the version numbers carefully, or the latest version
of the package available would be installed.

For example if your module is for version 2.6 of tryton, the line to add
would be

.. code-block:: python

install_requires = [

If you want to use weasyprint instead of whtmltopdf, it might be a good
idea to change the above line to

.. code-block:: python



The report file is missing

* Did you add the template file to the package_data in your ?
* Did you add the template file extension to the included files in

Authors and Contributors

This module was built at `Openlabs <>`_.

We gratefully acknowledge contributions by:

* `simon klemenc <>`_
* `Udo Spallek <>`_

Professional Support

This module is professionally supported by `Openlabs <>`_.
If you are looking for on-site teaching or consulting support, contact our
`sales <>`_ and `support
<>`_ teams.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openlabs_report_webkit- (8.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page