Package: openlabs_report_webkit
Webkit based PDF report engine==============================.. image:: https://travis-ci.org/openlabs/trytond-report-webkit.png?branch=develop:target: https://travis-ci.org/openlabs/trytond-report-webkitThis package allows you to build HTML based reports and then convert theminto PDFs using either `wkhtmltopdf` which uses the webkit rendering engine andQT. (WebKit is the engine of Apples Safari). or`Weasyprint <http://http://weasyprint.org/>`_The templates are written using `Jinja 2 <http://jinja.pocoo.org/>`_template engine. `Template Inheritance<http://jinja.pocoo.org/docs/templates/#template-inheritance>`_ is alsosupported to make it easier to extend existing emails and having a singletheme for all your emails.The package also supports Genshi Template`Inheritance <http://jinja.pocoo.org/docs/templates/#template-inheritance>`_.Using this in your projects===========================Instead of using the default report class from trytond.report use theReportWebkit class from this package instead... code-block:: pythonfrom openlabs_report_webkit import ReportWebkitclass UserReport(ReportWebkit):__name__ = 'res.user'@classmethoddef get_jinja_filters(cls, *args, **kwargs):"""Add my custom filters"""filters = super(UserReport, cls).get_jinja_filters(*args, **kwargs)filters.update({'nl2br': lambda value: value.replace('\n','<br>\n')})return filtersOutput Formats--------------To get PDF outputs (instead of standard html) ensure that the reportdefinition in xml clearly shows the extension as PDF. This could bechanged 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 olderversion which does not have support for features like page numbers at theend of each page. So remember to install the latest one published by themaintainers. For details refer to`wkhtmltopdf project website <http://wkhtmltopdf.org/>`_.Installing weasyprint`````````````````````Weasyprint is a much lighter option (in comparison to wkhtmltopdf) butwith lesser features. Weasyprint can be installed from PYPI.``pip install weasyprint``To use weasyprint, your report implementation class must explicitlyoverride the convert api to use weasyprint. Example:.. code-block:: python# TODO: an example hereTemplate Filters----------------Tryton HTML reports arrive with some builtin Template filters (in additionto the `built-in filters of Jinja2<http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters>`_) to makethings easier:dateformat(date, format='medium')`````````````````````````````````Format the date with the current language from the context. For otherpossible formats, refer the`babel documentation <http://babel.pocoo.org/docs/dates/#date-and-time>`_.Example.. code-block:: html+jinja<td>Date</td><td>{{ sale.date|dateformat }}</td>datetimeformat(datetime, format)````````````````````````````````Format the datetime with the current language from the context. For otherpossible formats, refer the`babel documentation <http://babel.pocoo.org/docs/dates/#date-and-time>`_.Example.. 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 <http://babel.pocoo.org/docs/api/numbers/?highlight=format_currency#babel.numbers.format_currency>`_Example.. code-block:: html+jinja<td>Total Value</td><td>{{ sale.total_amount|currencyformat(sale.currency.code) }}</td>modulepath(name)````````````````Get the absolute Path of a file within a moduleExample.. 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 yourTryton json_path2. 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 beavailable on the server, so you can only see the formatted pdfAdding as a dependency----------------------You can add the report toolkit as a dependent package of your trytonmodule by adding into the install_requires list on your setup.py script.Remember to specify the version numbers carefully, or the latest versionof the package available would be installed.For example if your module is for version 2.6 of tryton, the line to addwould be.. code-block:: pythoninstall_requires = [...,'openlabs_report_webkit>=2.6,<2.7'...,]If you want to use weasyprint instead of whtmltopdf, it might be a goodidea to change the above line to.. code-block:: python'openlabs_report_webkit[weasyprint]>=2.6,<2.7'Gotchas!========The report file is missing--------------------------* Did you add the template file to the package_data in your setup.py ?* Did you add the template file extension to the included files inMANIFEST ?Authors and Contributors------------------------This module was built at `Openlabs <http://www.openlabs.co.in>`_.We gratefully acknowledge contributions by:* `simon klemenc <https://github.com/hiaselhans>`_* `Udo Spallek <https://github.com/udono>`_Professional Support--------------------This module is professionally supported by `Openlabs <http://www.openlabs.co.in>`_.If you are looking for on-site teaching or consulting support, contact our`sales <mailto:sales@openlabs.co.in>`_ and `support<mailto:support@openlabs.co.in>`_ teams.