Skip to main content

Reporting engine based on Libreoffice (ODT -> ODT, ODT -> PDF, ODT -> DOC, ODT -> DOCX, ODS -> ODS, etc.)

Project description

License: AGPL-3

Report Py3o

The py3o reporting engine is a reporting engine for Odoo based on Libreoffice:

  • the report is created with Libreoffice (ODT or ODS),

  • the report is stored on the server in OpenDocument format (.odt or .ods file)

  • the report is sent to the user in OpenDocument format or in any output format supported by Libreoffice (PDF, HTML, DOC, DOCX, Docbook, XLS, etc.)

The key advantages of a Libreoffice-based reporting engine are:

  • no need to be a developper to create or modify a report: the report is created and modified with Libreoffice. So this reporting engine has a fully WYSIWYG report developpment tool!

  • For a PDF report in A4/Letter format, it’s easier to develop it with a tool such as Libreoffice that is designed to create A4/Letter documents than to develop it in HTML/CSS.

  • If you want your users to be able to modify the document after its generation by Odoo, just configure the document with ODT output (or DOC or DOCX) and the user will be able to modify the document with Libreoffice (or Word) after its generation by Odoo.

  • Easy development of spreadsheet reports in ODS format (XLS output possible).

This reporting engine is an alternative to Aeroo: these 2 reporting engines have similar features but their codes are completely different.

Installation

You must install 2 additionnal python libs:

pip install py3o.template
pip install py3o.formats

To allow the conversion of ODT or ODS reports to other formats (PDF, DOC, DOCX, etc.), you must install several additionnal components and Python libs:

  • Py3o Fusion server,

  • Py3o render server,

  • a Java Runtime Environment (JRE), which can be OpenJDK,

  • Libreoffice started in the background in headless mode,

  • the Java driver for Libreoffice (Juno).

It is also possible to use the Python driver for Libreoffice (PyUNO), but it is recommended to use the Java driver because it is more stable.

The installation procedure below uses the Java driver. It has been successfully tested on Ubuntu 16.04 LTS ; if you use another OS, you may have to change a few details.

Installation of py3o.fusion:

pip install py3o.fusion
pip install service-identity

Installation of py3o.renderserver:

pip install py3o.renderserver

Installation of Libreoffice and JRE on Debian/Ubuntu:

sudo apt-get install default-jre ure libreoffice-java-common libreoffice-writer

You may have to install additionnal fonts. For example, to have the special unicode symbols for phone/fax/email in the PDF reports generated by Py3o, you should install the following package:

sudo apt-get install fonts-symbola

At the end, with the dependencies, you should have the following py3o python libs:

% pip freeze | grep py3o
py3o.formats==0.3
py3o.fusion==0.8.6
py3o.renderclient==0.2
py3o.renderers.juno==0.8
py3o.renderserver==0.5.1
py3o.template==0.9.11
py3o.types==0.1.1

Start the Py3o Fusion server:

start-py3o-fusion --debug -s localhost

Start the Py3o render server:

start-py3o-renderserver --java=/usr/lib/jvm/default-java/jre/lib/amd64/server/libjvm.so --ure=/usr/share --office=/usr/lib/libreoffice --driver=juno --sofficeport=8997

On the output of the Py3o render server, the first line looks like:

DEBUG:root:Starting JVM: /usr/lib/jvm/default-java/jre/lib/amd64/server/libjvm.so with options: -Djava.class.path=/usr/local/lib/python2.7/dist-packages/py3o/renderers/juno/py3oconverter.jar:/usr/share/java/juh.jar:/usr/share/java/jurt.jar:/usr/share/java/ridl.jar:/usr/share/java/unoloader.jar:/usr/share/java/java_uno.jar:/usr/lib/libreoffice/program/classes/unoil.jar -Xmx150M

After -Djava.class.path, there is a list of Java libs with .jar extension ; check that each JAR file is really present on your filesystem. If one of the jar files is present in another directory, create a symlink that points to the real location of the file. If all the jar files are present on another directory, adapt the –ure= argument on the command line of Py3o render server.

To check that the Py3o Fusion server is running fine, visit the URL http://<IP_address>:8765/form. On this web page, under the section Target format, make sure that you have a line This server currently supports these formats: ods, odt, docx, doc, html, docbook, pdf, xls..

Configuration

For example, to replace the native invoice report by a custom py3o report, add the following XML file in your custom module:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="account.account_invoices" model="ir.actions.report.xml">
    <field name="report_type">py3o</field>
    <field name="py3o_filetype">odt</field>
    <field name="module">my_custom_module_base</field>
    <field name="py3o_template_fallback">report/account_invoice.odt</field>
</record>

</odoo>

where my_custom_module_base is the name of the custom Odoo module. In this example, the invoice ODT file is located in my_custom_module_base/report/account_invoice.odt.

It’s also possible to reference a template located in a trusted path of your Odoo server. In this case you must let the module entry empty and specify the path to the template as py3o_template_fallback.

<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="account.account_invoices" model="ir.actions.report.xml">
    <field name="report_type">py3o</field>
    <field name="py3o_filetype">odt</field>
    <field name="module">/field>
    <field name="py3o_template_fallback">/odoo/templates/py3o/report/account_invoice.odt</field>
</record>

</odoo>

Moreover you must also modify the odoo server configuration file to declare the allowed root directory for your py3o templates. Only templates located into this directory can be loaded by py3o report.

[options]
...

[report_py3o]
root_tmpl_path=/odoo/templates/py3o

If you want an invoice in PDF format instead of ODT format, the XML file should look like:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="local_py3o_server" model="py3o.server">
    <field name="url">http://localhost:8765/form</field>
</record>

<record id="account.account_invoices" model="ir.actions.report.xml">
    <field name="report_type">py3o</field>
    <field name="py3o_filetype">pdf</field>
    <field name="py3o_server_id" ref="local_py3o_server"/>
    <field name="module">my_custom_module_base</field>
    <field name="py3o_template_fallback">report/account_invoice.odt</field>
</record>

</odoo>

If you want to add a new py3o PDF report (and not replace a native report), the XML file should look like this:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="local_py3o_server" model="py3o.server">
    <field name="url">http://localhost:8765/form</field>
</record>

<record id="partner_summary_report" model="ir.actions.report.xml">
    <field name="name">Partner Summary</field>
    <field name="model">res.partner</field>
    <field name="report_name">res.partner.summary</field>
    <field name="report_type">py3o</field>
    <field name="py3o_filetype">pdf</field>
    <field name="py3o_server_id" ref="local_py3o_server"/>
    <field name="module">my_custom_module_base</field>
    <field name="py3o_template_fallback">report/partner_summary.odt</field>
</record>

<!-- Add entry in "Print" drop-down list -->
<record id="button_partner_summary_report" model="ir.values">
    <field name="key2">client_print_multi</field>
    <field name="model">res.partner</field>
    <field name="name">Partner Summary</field>
    <field name="value" eval="'ir.actions.report.xml,%d'%partner_summary_report" />
</record>

</odoo>

Usage

Try me on Runbot

Known issues / Roadmap

  • generate barcode ?

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback.

Credits

Contributors

Maintainer

Odoo Community Association

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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