Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 128 additions & 8 deletions report_py3o/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Report Py3o

The py3o reporting engine is a reporting engine for Odoo based on `Libreoffice <http://www.libreoffice.org/>`_:

* the report is created with Libreoffice (ODT or ODS),
* the report is created with Libreoffice (ODT or ODS files) or any other software that generate files in `OpenDocument <https://en.wikipedia.org/wiki/OpenDocument>`_ format,
* 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.)

Expand All @@ -34,20 +34,140 @@ You must install 2 additionnal python libs:
pip install py3o.template
pip install py3o.formats

If you want to convert the ODT or ODS report in another format, you need several additionnal components and Python libs:
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 <https://bitbucket.org/faide/py3o.fusion>`_
* `Py3o render server <https://bitbucket.org/faide/py3o.renderserver>`_
* Libreoffice started in the background in headless mode.
* `Py3o Fusion server <https://bitbucket.org/faide/py3o.fusion>`_,
* `Py3o render server <https://bitbucket.org/faide/py3o.renderserver>`_,
* a Java Runtime Environment (JRE), which can be OpenJDK,
* Libreoffice started in the background in headless mode,
* the Java driver for Libreoffice (Juno).

TODO : continue
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:

.. code::

pip install py3o.fusion
pip install service-identity

Installation of py3o.renderserver:

.. code::

pip install py3o.renderserver

Installation of Libreoffice and JRE on Debian/Ubuntu:

.. code::

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

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

.. code::

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

Start the Py3o Fusion server:

.. code::

start-py3o-fusion --debug -s localhost

Start the Py3o render server:

.. code::

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

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

.. code::

DEBUG:root:Starting JVM: /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so with options: -Djava.class.path=/usr/local/lib/python2.7/dist-packages/py3o/renderers/juno/py3oconverter.jar:/usr/lib/ure/share/java/juh.jar:/usr/lib/ure/share/java/jurt.jar:/usr/lib/ure/share/java/ridl.jar:/usr/lib/ure/share/java/unoloader.jar:/usr/lib/ure/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. On Ubuntu 16.04 LTS, the package *ure* installs several libs in another directory:

* /usr/lib/ure/share/java/juh.jar is located in /usr/share/java/juh.jar
* /usr/lib/ure/share/java/jurt.jar is located in /usr/share/java/jurt.jar
* /usr/lib/ure/share/java/ridl.jar is located in /usr/share/java/ridl.jar
* /usr/lib/ure/share/java/unoloader.jar is located in /usr/share/java/unoloader.jar
* /usr/lib/ure/share/java/java_uno.jar is located in /usr/share/java/java_uno.jar

To work around this problem, you can create a symlink:

.. code::

sudo ln -s /usr /ure

and then use **--ure=/** instead of **--ure=/usr/lib** in the command line of *start-py3o-renderserver*.

Start Libreoffice in headless mode:

.. code::

libreoffice --nologo --norestore --invisible --headless --nocrashreport --nofirststartwizard --nodefault --accept="socket,host=localhost,port=8997;urp;"

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
=============

If you want to convert the report in another format, go to the menu *Configuration > Technical > Reports > Py3o > Py3o Servers* and create a new Py3o server with its URL (for example: http://localhost:8765/form).
For example, to replace the native invoice report by a custom py3o report, add the following XML file in your custom module:

.. code::

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

<record id="account.account_invoices" model="ir.actions.report.xml">
<field name="name">Invoice</field>
<field name="model">account.invoice</field>
<field name="report_name">account.report_invoice</field>
<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*.

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

.. code::

<?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="name">Invoice</field>
<field name="model">account.invoice</field>
<field name="report_name">account.report_invoice</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/account_invoice.odt</field>
</record>

</odoo>

TODO: continue

Usage
=====
Expand Down
1 change: 1 addition & 0 deletions report_py3o/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import ir_actions_report_xml
from . import py3o_template
from . import py3o_server
from . import py3o_report
59 changes: 13 additions & 46 deletions report_py3o/models/ir_actions_report_xml.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright 2013 XCG Consulting (http://odoo.consulting)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import os
import logging
from openerp import api, fields, models, SUPERUSER_ID, _
from openerp.report.interface import report_int
from openerp import api, fields, models, _
from openerp.exceptions import ValidationError
from openerp import addons
from ..py3o_parser import Py3oParser


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -85,44 +82,14 @@ def _get_py3o_filetypes(self):
))
report_type = fields.Selection(selection_add=[('py3o', "Py3o")])

@api.cr
def _lookup_report(self, cr, name):
"""Look up a report definition.
"""

# First lookup in the deprecated place, because if the report
# definition has not been updated, it is more likely the correct
# definition is there. Only reports with custom parser
# specified in Python are still there.
if 'report.' + name in report_int._reports:
new_report = report_int._reports['report.' + name]
if not isinstance(new_report, Py3oParser):
new_report = None
else:
report_data = self.search_read(
cr, SUPERUSER_ID,
[("report_name", "=", name),
("report_type", "=", "py3o")],
['parser', 'model', 'report_name', 'report_rml', 'header'],
limit=1)
if report_data:
report_data = report_data[0]
kwargs = {}
if report_data['parser']:
kwargs['parser'] = getattr(addons, report_data['parser'])

new_report = Py3oParser(
'report.' + report_data['report_name'],
report_data['model'],
os.path.join('addons', report_data['report_rml'] or '/'),
header=report_data['header'],
register=False,
**kwargs
)
else:
new_report = None

if new_report:
return new_report
else:
return super(IrActionsReportXml, self)._lookup_report(cr, name)
@api.model
def render_report(self, res_ids, name, data):
action_py3o_report = self.search(
[("report_name", "=", name),
("report_type", "=", "py3o")])
if action_py3o_report:
return self.env['py3o.report'].create({
'ir_actions_report_xml_id': action_py3o_report.id
}).create_report(res_ids, data)
return super(IrActionsReportXml, self).render_report(
res_ids, name, data)
Loading