Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] report_py3o #976

Open
wants to merge 135 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
fa3a1da
Move to report_py3o after import from HG
lmignon Oct 3, 2016
c6b4c0c
Add setup
lmignon Oct 3, 2016
bc4f99a
[FIX] View inheritance may not use attribute 'string' as a selector.
lmignon Oct 3, 2016
70f2a48
[IMP] New API + Short Hearder
lmignon Oct 4, 2016
3ee04e4
Remove unicode string
lmignon Oct 4, 2016
f2e3bc9
[IMP] Add the possiblity to get the template from an absolute path on…
lmignon Oct 4, 2016
1c4ff5e
[IMP] Allow user to use local fusion
lmignon Oct 4, 2016
9f5962b
Add a simple way to extend the parser context
lmignon Oct 4, 2016
baae407
Remove ACL on removed model
lmignon Oct 4, 2016
4f8a840
Improve filetype selection name
lmignon Oct 4, 2016
cccb88c
Fix native flag
lmignon Oct 4, 2016
380de57
fixed missing comma in model definition
faide Oct 4, 2016
97996f3
Add simple tests and fix call to fusion server
lmignon Oct 4, 2016
190bbce
Fix skip fusion on server when the fusion is local
lmignon Oct 4, 2016
9d61ff9
Improve tests
lmignon Oct 4, 2016
fb45480
Replace openerp element by odoo
lmignon Oct 4, 2016
d43d384
Small usability improvements
alexis-via Oct 4, 2016
045ec9a
Take into accounts most remarks of @lasley
alexis-via Oct 5, 2016
dbe4144
Replace plain SQL by orm
lmignon Oct 6, 2016
bd40b3e
rename module ir_report to ir_actions_report_xml
lmignon Oct 6, 2016
0b166bc
Add more tests and fixes issues found by tests
lmignon Oct 6, 2016
cabf99c
[FIX] Check constrains only if report_type == 'py3o'
lmignon Oct 12, 2016
a16a522
report_py3o: full installation procedure in README
alexis-via Oct 14, 2016
431aab7
Port report_py3o to Odoo v10
alexis-via Oct 14, 2016
a85a42c
Update version numbers
alexis-via Oct 14, 2016
b72e82f
PEP8 fix
alexis-via Oct 14, 2016
62bf5df
Update README
alexis-via Nov 4, 2016
f51c8ac
FIX double dot in filename
alexis-via Dec 19, 2016
b7caf5a
Add access to report_xml object in report
alexis-via Dec 19, 2016
a8c933c
FIX Adapt test suite to my recent commit to avoid double dot on filen…
alexis-via Dec 20, 2016
eed40a4
[IMP] Escape 'False' when rendering value
lmignon Nov 16, 2016
fbc3ba3
[IMP] Replace old style parser by TransientModel
lmignon Dec 17, 2016
901ca4b
[FIX] imports
Dec 22, 2016
219fc5f
[IMP] Minimizes memory consumption
lmignon Dec 23, 2016
d609da6
* travis.yml
Jan 9, 2017
06720bb
Update and improve README instructions to setup py3o
alexis-via Jan 25, 2017
bbcc350
[IMP] Allow to override/extend the way we get the fallback template
lmignon Jan 25, 2017
1874837
[FIX] report_py3o: fix exception when report must be saved as attache…
lmignon Feb 23, 2017
681e3cd
OCA Transbot updated translations from Transifex
oca-transbot Feb 25, 2017
2a106f9
[FIX] delete PDF invoice attachment on invoice back to draft (native …
alexis-via Mar 2, 2017
e00e291
[IMP] report_py3o: update authors and contributors
lmignon Mar 6, 2017
38b8a84
OCA Transbot updated translations from Transifex
oca-transbot Mar 11, 2017
1fc2b5c
[IMP] report_py3o: prevent injections when retrieving the template fr…
lmignon Mar 8, 2017
68a2beb
OCA Transbot updated translations from Transifex
oca-transbot Mar 18, 2017
065ed6d
report_py3o: bump version following last merge
sbidoul Mar 22, 2017
e87b05f
Fix py3o freeze when using server fusion
guewen Apr 3, 2017
e4c4334
Pass option for escaping False values to server
guewen Apr 5, 2017
50d9cc7
Add option py3o_multi_in_one for Py3o reports
alexis-via Apr 12, 2017
d42e845
OCA Transbot updated translations from Transifex
oca-transbot May 1, 2017
effab43
[FIX] report_py3o: must return the path to the report
lmignon May 30, 2017
843dd56
[IMP] report_py3o: Take into account print_report_name
lmignon Feb 17, 2017
ffe3e12
OCA Transbot updated translations from Transifex
oca-transbot Jun 3, 2017
eac82dc
[IMP] report_py3o: Allows to interpret \n and \t in texts, cleans htm…
omar7r Oct 31, 2017
2141a40
[FIX] Deletes an unnecessary function call
omar7r Nov 7, 2017
c33c328
[FIX] report_py3o: Removes api.one
omar7r Nov 9, 2017
dad5603
[FIX] report_py3o: Import new dependencies in try...except
omar7r Nov 9, 2017
44b64fe
[UPD] report_py3o: Bump version
omar7r Nov 10, 2017
f5c633a
OCA Transbot updated translations from Transifex
oca-transbot Nov 25, 2017
e73d551
[RFR] split off the fusion server to its own module
hbrunn Dec 17, 2017
d93ded9
Improve README.rst for report_py3o* modules
alexis-via Jan 10, 2018
0926fa8
[ADD] migration script to install report_py3o_fusion_server on upgrades
hbrunn Jan 11, 2018
08f6bf2
OCA Transbot updated translations from Transifex
oca-transbot Jan 16, 2018
7374a3a
[FIX] fallback to libreoffice conversion when no server is configured
hbrunn Mar 21, 2018
b7dd5cc
[FIX] report_py3o: Bump version number
pedrobaeza Mar 26, 2018
0c2bd2d
[FIX]report_py3o: Escape correctly html characters.
jesusVMayor Dec 19, 2017
81069d2
[IMP] check for template data, not for the id
hbrunn Apr 16, 2018
bb589cc
[FIX] If this is not a py3o report, do nothing at all. In some cases …
SimoRubi May 2, 2018
7912366
report_py3o: mention formatLang in README
sbidoul May 16, 2018
63a6a87
report_py3o_fusion_server: Add support for PDF Export options of libr…
alexis-via Apr 24, 2018
06effb6
[UPD] Update report_py3o.pot
oca-travis Jun 23, 2018
a23af3f
Translated using Weblate (Français)
kryskool Jul 18, 2018
6c35482
[MIG] report_py3o, report_py3o_fusion_server: Migration to 12.0
lmignon Nov 26, 2018
f73e838
[IMP] report_py2o: cleanup js
lmignon Nov 27, 2018
c514f20
[12.0][MIG] improvement py3o_report_extender
Nov 29, 2018
b43bc79
Update i18n
sbejaoui Dec 4, 2018
dab2788
[FIX] report_py3o: Use the right naming convention for the render method
lmignon Jan 8, 2019
e7e2ccc
[IMP] report_py3o: remove obsolete methods
lmignon Jan 8, 2019
1791ea6
[IMP] report_py3o: Document new methods available into the parser con…
lmignon Jan 31, 2019
cf49f61
[FIX] report_py3o: Add missing method _merge_pdf.
lmignon Jan 31, 2019
0ab4284
[IMP][FIX] py3o_report, py3o_report_fusion_server: Compute the availa…
lmignon Feb 1, 2019
e2e0120
[FIX] report_py3o: Add missing 'user' and 'lang' into the parser context
lmignon Feb 1, 2019
d923886
[IMP] py3o_report: Allow to specify the lang when calling o_format_lang
lmignon Feb 1, 2019
6508e0f
[FIX] report_py3o: Access to ir.config_parameter with sudo
lmignon Feb 5, 2019
30d8f31
[UPD] Update report_py3o.pot
oca-travis Mar 12, 2019
a48f3b4
Update translation files
oca-transbot Mar 17, 2019
ef18f63
[UPD] Update report_py3o.pot
oca-travis Jun 12, 2019
f998e20
Update translation files
oca-transbot Jun 16, 2019
a4c5d77
Update README for report_py3o and report_py3o_fusion_server (#306)
alexis-via Jul 18, 2019
4ce0557
[FIX] report_py3o readme structure
sbidoul Jul 31, 2019
969e951
[UPD] README.rst
OCA-git-bot Jul 31, 2019
9e397c2
[IMP] report_py3o, report_py3o_fusion_server: black, isort
lmignon Nov 19, 2019
b2b93af
[MIG] report_py3o, report_py3o_fusion_server: Migration to 13.0
lmignon Nov 19, 2019
ec56e32
Make sure value is always set for computed fields
dupski Oct 28, 2019
578c738
[12.0][FIX] - report_py3o: run libreoffice in an isolated user instal…
sbejaoui Jan 23, 2020
1c772f5
[FIX] report_py3o: prettier xml after merge with master
lmignon May 12, 2020
4858579
[FIX] make prettier happy
sbidoul May 13, 2020
ec6b845
[UPD] Update report_py3o.pot
oca-travis Jun 17, 2020
ba9d326
[UPD] README.rst
OCA-git-bot Jun 18, 2020
c9258bf
Update translation files
oca-transbot Jun 18, 2020
8c1d68f
Update translation files
oca-transbot Aug 16, 2020
51063ec
[14.0][MIG] report_py3o: Migration to 14.0
elmeriniemela Oct 21, 2020
0a44eca
Update report_py3o/models/ir_actions_report.py
elmeriniemela Nov 7, 2020
9230fd1
[MIG] Use safe_eval wrapped time module. Fix deprecation warnings.
elmeriniemela Feb 2, 2021
cd66ff1
[IMP] Add ability to include properly formatted datetime field in a r…
elmeriniemela Nov 5, 2021
62d8051
[IMP] Workaround for genshi DeprecationWarning that makes runbot buil…
elmeriniemela Nov 7, 2021
7d2cc65
[IMP] Cleanup unnecessary imports
elmeriniemela Nov 7, 2021
c2c809f
[IMP] Remove except of IOError as its an alias to OSError in python3
elmeriniemela Nov 7, 2021
a6b907c
run pre-commit
leemannd Nov 23, 2021
468de98
[UPD] Update report_py3o.pot
oca-travis Dec 9, 2021
c4c2e50
[UPD] README.rst
OCA-git-bot Dec 9, 2021
2b3b531
[MIG] report_py3o: Migration to 15.0
phuctranfxvn May 15, 2022
40c0012
[MIG] report_py3o to v16
alexis-via Dec 12, 2022
5bd65ca
[UPD] Update report_py3o.pot
Aug 23, 2023
2956eaa
[UPD] README.rst
OCA-git-bot Aug 23, 2023
6423985
[UPD] README.rst
OCA-git-bot Sep 3, 2023
501b5bb
Update translation files
weblate Sep 3, 2023
cd5a3eb
Translated using Weblate (Spanish)
Ivorra78 Sep 7, 2023
95a4ae7
Translated using Weblate (Spanish (Argentina))
ibuioli Sep 10, 2023
d5c14cb
Translated using Weblate (Italian)
mymage Sep 13, 2023
6a54fae
Update translation files
weblate Oct 10, 2023
6d220de
Replaced `mktemp` with `mkstemp`
fazledyn-or Nov 8, 2023
f11657c
Reformatted using pre-commit
fazledyn-or Nov 9, 2023
4fd3036
[BOT] post-merge updates
OCA-git-bot Dec 8, 2023
c5ccf05
Translated using Weblate (Italian)
mymage Jan 19, 2024
0127938
[IMP] remove python libs included in odoo from requirements
CRogos Apr 4, 2024
128a17a
[BOT] post-merge updates
OCA-git-bot Apr 4, 2024
9fb1846
Translated using Weblate (Swedish)
jakobkrabbe Jun 27, 2024
fa4a274
[FIX] _py3o_parser_context: fix call to format_date in old_format_lang
jdoutreloux Jan 8, 2024
e6125c7
[BOT] post-merge updates
OCA-git-bot Jul 24, 2024
3c75858
[IMP] report_py3o: use the standard file name behavior when zipping r…
ThomasBinsfeld Dec 18, 2023
a942f2b
[BOT] post-merge updates
OCA-git-bot Sep 5, 2024
ea4558f
[IMP] report_py3o: pre-commit auto fixes
bug2point0 Sep 11, 2024
61cb3d1
[17.0] [MIG] report_py3o
bug2point0 Sep 14, 2024
5683f47
[IMP] replace deprecated pkg_resources with importlib.resources
bug2point0 Sep 14, 2024
e2e6be9
[18.0][MIG] report_py3o
sbejaoui Feb 11, 2025
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
661 changes: 661 additions & 0 deletions report_py3o/LICENSE

Large diffs are not rendered by default.

232 changes: 232 additions & 0 deletions report_py3o/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
==================
Py3o Report Engine
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6475c7e18340a01f1070b14e0c403646da2a1e1381b73969ba16b91c163d4db7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/18.0/report_py3o
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-report_py3o
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

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 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 developer to create or modify a report: the report is
created and modified with Libreoffice. So this reporting engine has a
full WYSIWYG report development 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, also some print
peculiarities (backgrounds, margin boxes) are not very well supported
by the HTML/CSS based solutions.
- 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 module *report_py3o* is the base module for the Py3o reporting
engine. If used alone, it will spawn a libreoffice process for each ODT
to PDF (or ODT to DOCX, ..) document conversion. This is slow and can
become a problem if you have a lot of reports to convert from ODT to
another format. In this case, you should consider the additionnal module
*report_py3o_fusion_server* which is designed to work with a libreoffice
daemon. With *report_py3o_fusion_server*, the technical environnement is
more complex to setup because you have to install additionnal software
components and run 2 daemons, but you have much better performances and
you can configure the libreoffice PDF export options in Odoo (allows to
generate PDF forms, PDF/A documents, password-protected PDFs,
watermarked PDFs, etc.).

This reporting engine is an alternative to
[Aeroo](https://github.com/aeroo-community/aeroo_reports): these two
reporting engines have similar features but their implementation is
entirely different. You cannot use aeroo templates as drop in
replacement though, you'll have to change a few details.

**Table of contents**

.. contents::
:local:

Installation
============

Install the required python libs:

:literal:`` pip install py3o.template pip install py3o.formats`\ \`

To allow the conversion of ODT or ODS reports to other formats (PDF,
DOC, DOCX, etc.), install libreoffice:

:literal:`` apt-get --no-install-recommends install libreoffice`\ \`

Configuration
=============

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

:literal:`` <?xml version="1.0" encoding="utf-8"?> <odoo> <record id="account.account_invoices" model="ir.actions.report"> <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*.

:literal:`` <?xml version="1.0" encoding="utf-8"?> <odoo> <record id="account.account_invoices" model="ir.actions.report"> <field name="report_type">py3o</field> <field name="py3o_filetype">odt</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.

:literal:`` [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:

:literal:`` <?xml version="1.0" encoding="utf-8"?> <odoo> <record id="account.account_invoices" model="ir.actions.report"> <field name="report_type">py3o</field> <field name="py3o_filetype">pdf</field> <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:

:literal:`` <?xml version="1.0" encoding="utf-8"?> <odoo> <record id="partner_summary_report" model="ir.actions.report"> <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="module">my_custom_module_base</field> <field name="py3o_template_fallback">report/partner_summary.odt</field> <!-- Add entry in "Print" drop-down list --> <field name="binding_type">report</field> <field name="binding_model_id" ref="base.model_res_partner"/> </record> </odoo>`\ \`

## Configuration parameters

py3o.conversion_command The command to be used to run the conversion,
libreoffice by default. If you change this, whatever you set here must
accept the parameters --headless --convert-to $ext $file and put the
resulting file into $file's directory with extension $ext. The command
will be started in $file's directory.

Usage
=====

The templating language is [extensively
documented](http://py3otemplate.readthedocs.io/en/latest/templating.html),
the records are exposed in libreoffice as objects, on which you can also
call functions.

## Available functions and objects

user Browse record of current user

lang The user's company's language as string (ISO code)

b64decode base64.b64decode

format_multiline_value(string) Generate the ODF equivalent of <br/> and
  for multiline fields (ODF is XML internally, so those would be skipped
otherwise)

html_sanitize(string) Sanitize HTML string

time Python's time module

display_address(partner) Return a formatted string of the partner's
address

o_format_lang(value, lang_code=False, digits=None, grouping=True,
monetary=False, dp=False, currency_obj=False, no_break_space=True)
Return a formatted numeric or monetary value according to the context
language and timezone

o_format_date(value, lang_code=False, date_format=False) Return a
formatted date or time value according to the context language and
timezone

## Sample report templates

Sample py3o report templates for the main Odoo native reports (invoice,
sale order, purchase order, picking, etc.) are available on the Github
project
[odoo-py3o-report-templates](https://github.com/akretion/odoo-py3o-report-templates).

Known issues / Roadmap
======================

- generate barcode ?
- add more detailed example in demo file to showcase features
- add migration guide aeroo -> py3o

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_py3o%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* XCG Consulting
* ACSONE SA/NV

Contributors
------------

- Florent Aide ([XCG Consulting](http://odoo.consulting/))
- Laurent Mignon <<laurent.mignon@acsone.eu>>,
- Alexis de Lattre <<alexis.delattre@akretion.com>>,
- Guewen Baconnier <<guewen.baconnier@camptocamp.com>>
- Omar Casti??eira <<omar@comunitea.com>>
- Holger Brunn <<hbrunn@therp.nl>>
- Phuc Tran Thanh <<phuc@trobz.com>>
- Souheil Bejaoui <<souheil.bejaoui@acsone.eu>>,

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/18.0/report_py3o>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions report_py3o/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controllers
29 changes: 29 additions & 0 deletions report_py3o/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2013 XCG Consulting (http://odoo.consulting)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Py3o Report Engine",
"summary": "Reporting engine based on Libreoffice (ODT -> ODT, "
"ODT -> PDF, ODT -> DOC, ODT -> DOCX, ODS -> ODS, etc.)",
"version": "18.0.1.0.0",
"category": "Reporting",
"license": "AGPL-3",
"author": "XCG Consulting, ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/reporting-engine",
"depends": ["web"],
"external_dependencies": {
"python": ["py3o.template", "py3o.formats"],
"deb": ["libreoffice"],
},
"assets": {
"web.assets_backend": [
"report_py3o/static/src/js/py3oactionservice.esm.js",
],
},
"data": [
"security/ir.model.access.csv",
"views/py3o_template.xml",
"views/ir_actions_report.xml",
"demo/report_py3o.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions report_py3o/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
95 changes: 95 additions & 0 deletions report_py3o/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import json
import mimetypes
from urllib.parse import parse_qs

from werkzeug import exceptions
from werkzeug.datastructures import MultiDict

from odoo.http import content_disposition, request, route, serialize_exception
from odoo.tools import html_escape

from odoo.addons.web.controllers.report import ReportController as ReportControllerBase


class ReportController(ReportControllerBase):
@route()
def report_routes(self, reportname, docids=None, converter=None, **data):
if converter != "py3o":
return super().report_routes(

Check warning on line 20 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L20

Added line #L20 was not covered by tests
reportname=reportname, docids=docids, converter=converter, **data
)
context = dict(request.env.context)

Check warning on line 23 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L23

Added line #L23 was not covered by tests

if docids:
docids = [int(i) for i in docids.split(",")]

Check warning on line 26 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L26

Added line #L26 was not covered by tests
if data.get("options"):
data.update(json.loads(data.pop("options")))

Check warning on line 28 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L28

Added line #L28 was not covered by tests
if data.get("context"):
# Ignore 'lang' here, because the context in data is the
# one from the webclient *but* if the user explicitely wants to
# change the lang, this mechanism overwrites it.
data["context"] = json.loads(data["context"])

Check warning on line 33 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L33

Added line #L33 was not covered by tests
if data["context"].get("lang"):
del data["context"]["lang"]
context.update(data["context"])

Check warning on line 36 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L35-L36

Added lines #L35 - L36 were not covered by tests

ir_action = request.env["ir.actions.report"]
action_py3o_report = ir_action.get_from_report_name(

Check warning on line 39 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L38-L39

Added lines #L38 - L39 were not covered by tests
reportname, "py3o"
).with_context(**context)
if not action_py3o_report:
raise exceptions.HTTPException(

Check warning on line 43 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L43

Added line #L43 was not covered by tests
description="Py3o action report not found for report_name "
f"{reportname}"
)
res, filetype = ir_action._render(reportname, docids, data)
filename = action_py3o_report.gen_report_download_filename(docids, data)

Check warning on line 48 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L47-L48

Added lines #L47 - L48 were not covered by tests
if not filename.endswith(filetype):
filename = f"{filename}.{filetype}"
content_type = mimetypes.guess_type("x." + filetype)[0]
http_headers = [

Check warning on line 52 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L50-L52

Added lines #L50 - L52 were not covered by tests
("Content-Type", content_type),
("Content-Length", len(res)),
("Content-Disposition", content_disposition(filename)),
]
return request.make_response(res, headers=http_headers)

Check warning on line 57 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L57

Added line #L57 was not covered by tests

@route()
def report_download(self, data, context=None, token=None):
"""This function is used by 'qwebactionmanager.js' in order to trigger
the download of a py3o/controller report.

:param data: a javascript array JSON.stringified containg report
internal url ([0]) and type [1]
:returns: Response with a filetoken cookie and an attachment header
"""
requestcontent = json.loads(data)
url, report_type = requestcontent[0], requestcontent[1]

Check warning on line 69 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L68-L69

Added lines #L68 - L69 were not covered by tests
if "py3o" not in report_type:
return super().report_download(data, context=context, token=token)
try:
reportname = url.split("/report/py3o/")[1].split("?")[0]
docids = None

Check warning on line 74 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L71-L74

Added lines #L71 - L74 were not covered by tests
if "/" in reportname:
reportname, docids = reportname.split("/")

Check warning on line 76 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L76

Added line #L76 was not covered by tests

if docids:
# Generic report:
response = self.report_routes(

Check warning on line 80 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L80

Added line #L80 was not covered by tests
reportname, docids=docids, converter="py3o"
)
else:
# Particular report:
# decoding the args represented in JSON
data = list(MultiDict(parse_qs(url.split("?")[1])).items())
response = self.report_routes(

Check warning on line 87 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L86-L87

Added lines #L86 - L87 were not covered by tests
reportname, converter="py3o", **dict(data)
)
response.set_cookie("fileToken", context)
return response
except Exception as e:
se = serialize_exception(e)
error = {"code": 200, "message": "Odoo Server Error", "data": se}
return request.make_response(html_escape(json.dumps(error)))

Check warning on line 95 in report_py3o/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

report_py3o/controllers/main.py#L90-L95

Added lines #L90 - L95 were not covered by tests
20 changes: 20 additions & 0 deletions report_py3o/demo/report_py3o.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2016 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="res_users_report_py3o" model="ir.actions.report">
<field name="name">Py3o Demo Report</field>
<field name="type">ir.actions.report</field>
<field name="model">res.users</field>
<field name="report_name">py3o_user_info</field>
<field name="report_type">py3o</field>
<field name="py3o_filetype">odt</field>
<field name="module">report_py3o</field>
<field name="py3o_template_fallback">demo/res_user.odt</field>
<field
name="print_report_name"
>object.name.replace(' ', '_') + '-demo.odt'</field>
<field name="binding_model_id" ref="base.model_res_users" />
<field name="binding_type">report</field>
</record>
</odoo>
Binary file added report_py3o/demo/res_user.odt
Binary file not shown.
Loading