-
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by HviorForgeFlow
- Loading branch information
Showing
35 changed files
with
2,160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
================ | ||
Base report xlsx | ||
================ | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:0cdb111ad7244341d95a941ae568244595e3dd96993c951fd16992da581afb0f | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Mature | ||
.. |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_xlsx | ||
: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_xlsx | ||
: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| | ||
|
||
This module provides a basic report class to generate xlsx report. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Installation | ||
============ | ||
|
||
Make sure you have ``xlsxwriter`` Python module installed: | ||
|
||
:: | ||
|
||
$ pip3 install xlsxwriter | ||
|
||
For testing it is also necessary ``xlrd`` Python module installed: | ||
|
||
:: | ||
|
||
$ pip3 install xlrd | ||
|
||
Usage | ||
===== | ||
|
||
An example of XLSX report for partners on a module called | ||
\`module_name\`: | ||
|
||
A python class : | ||
|
||
:: | ||
|
||
from odoo import models | ||
|
||
class PartnerXlsx(models.AbstractModel): | ||
_name = 'report.module_name.report_name' | ||
_inherit = 'report.report_xlsx.abstract' | ||
|
||
def generate_xlsx_report(self, workbook, data, partners): | ||
for obj in partners: | ||
report_name = obj.name | ||
# One sheet by partner | ||
sheet = workbook.add_worksheet(report_name[:31]) | ||
bold = workbook.add_format({'bold': True}) | ||
sheet.write(0, 0, obj.name, bold) | ||
|
||
To manipulate the ``workbook`` and ``sheet`` objects, refer to the | ||
`documentation <http://xlsxwriter.readthedocs.org/>`__ of | ||
``xlsxwriter``. | ||
|
||
A report XML record : | ||
|
||
:: | ||
|
||
<record id="action_report_partner_xlsx" model="ir.actions.report"> | ||
<field name="name">Print to XLSX</field> | ||
<field name="model">res.partner</field> | ||
<field name="report_type">xlsx</field> | ||
<field name="report_name">module_name.report_name</field> | ||
<field name="report_file">module_name.report_file</field> | ||
<field name="binding_model_id" ref="res.partner"/> | ||
<field name="binding_type">report</field> | ||
<field name="attachment_use" eval="False"/> | ||
</record> | ||
|
||
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_xlsx%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 | ||
------- | ||
|
||
* ACSONE SA/NV | ||
* Creu Blanca | ||
|
||
Contributors | ||
------------ | ||
|
||
- Adrien Peiffer <[email protected]> | ||
- Sébastien Alix <[email protected]> | ||
- Stéphane Bidoul <[email protected]> | ||
- Enric Tobella <[email protected]> | ||
- Graeme Gellatly <[email protected]> | ||
- Cristian Salamea <[email protected]> | ||
- Rod Schouteden <[email protected]> | ||
- Eugene Molotov <[email protected]> | ||
- Christopher Ormaza <[email protected]> | ||
- Houzéfa Abbasbhay <[email protected]> | ||
- Le Dinh Tien <[email protected]> | ||
|
||
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_xlsx>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import controllers | ||
from . import models | ||
from . import report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2015 ACSONE SA/NV (<http://acsone.eu>) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Base report xlsx", | ||
"summary": "Base module to create xlsx report", | ||
"author": "ACSONE SA/NV," "Creu Blanca," "Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/reporting-engine", | ||
"category": "Reporting", | ||
"version": "18.0.1.0.0", | ||
"development_status": "Mature", | ||
"license": "AGPL-3", | ||
"external_dependencies": {"python": ["xlsxwriter", "xlrd"]}, | ||
"depends": ["base", "web"], | ||
"demo": ["demo/report.xml"], | ||
"installable": True, | ||
"assets": { | ||
"web.assets_backend": [ | ||
"report_xlsx/static/src/js/report/action_manager_report.esm.js", | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright (C) 2017 Creu Blanca | ||
# Copyright 2021 ForgeFlow S.L. | ||
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). | ||
|
||
import json | ||
import logging | ||
|
||
from werkzeug.urls import url_decode | ||
|
||
from odoo.http import ( | ||
content_disposition, | ||
request, | ||
route, | ||
) | ||
from odoo.http import ( | ||
serialize_exception as _serialize_exception, | ||
) | ||
from odoo.tools import html_escape | ||
from odoo.tools.safe_eval import safe_eval, time | ||
|
||
from odoo.addons.web.controllers.report import ReportController | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ReportController(ReportController): | ||
@route() | ||
def report_routes(self, reportname, docids=None, converter=None, **data): | ||
if converter == "xlsx": | ||
report = request.env["ir.actions.report"]._get_report_from_name(reportname) | ||
context = dict(request.env.context) | ||
if docids: | ||
docids = [int(i) for i in docids.split(",")] | ||
if data.get("options"): | ||
data.update(json.loads(data.pop("options"))) | ||
if data.get("context"): | ||
data["context"] = json.loads(data["context"]) | ||
context.update(data["context"]) | ||
xlsx = report.with_context(**context)._render_xlsx( | ||
reportname, docids, data=data | ||
)[0] | ||
xlsxhttpheaders = [ | ||
( | ||
"Content-Type", | ||
"application/vnd.openxmlformats-" | ||
"officedocument.spreadsheetml.sheet", | ||
), | ||
("Content-Length", len(xlsx)), | ||
] | ||
return request.make_response(xlsx, headers=xlsxhttpheaders) | ||
return super().report_routes(reportname, docids, converter, **data) | ||
|
||
@route() | ||
def report_download(self, data, context=None, token=None): | ||
requestcontent = json.loads(data) | ||
url, report_type = requestcontent[0], requestcontent[1] | ||
if report_type == "xlsx": | ||
try: | ||
reportname = url.split("/report/xlsx/")[1].split("?")[0] | ||
docids = None | ||
if "/" in reportname: | ||
reportname, docids = reportname.split("/") | ||
if docids: | ||
# Generic report: | ||
response = self.report_routes( | ||
reportname, docids=docids, converter="xlsx", context=context | ||
) | ||
else: | ||
# Particular report: | ||
data = dict( | ||
url_decode(url.split("?")[1]).items() | ||
) # decoding the args represented in JSON | ||
if "context" in data: | ||
context, data_context = ( | ||
json.loads(context or "{}"), | ||
json.loads(data.pop("context")), | ||
) | ||
context = json.dumps({**context, **data_context}) | ||
response = self.report_routes( | ||
reportname, converter="xlsx", context=context, **data | ||
) | ||
|
||
report = request.env["ir.actions.report"]._get_report_from_name( | ||
reportname | ||
) | ||
filename = f"{report.name}.xlsx" | ||
|
||
if docids: | ||
ids = [int(x) for x in docids.split(",")] | ||
obj = request.env[report.model].browse(ids) | ||
if report.print_report_name and not len(obj) > 1: | ||
report_name = safe_eval( | ||
report.print_report_name, {"object": obj, "time": time} | ||
) | ||
filename = f"{report_name}.xlsx" | ||
if not response.headers.get("Content-Disposition"): | ||
response.headers.add( | ||
"Content-Disposition", content_disposition(filename) | ||
) | ||
return response | ||
except Exception as e: | ||
_logger.exception("Error while generating report %s", reportname) | ||
se = _serialize_exception(e) | ||
error = {"code": 200, "message": "Odoo Server Error", "data": se} | ||
return request.make_response(html_escape(json.dumps(error))) | ||
else: | ||
return super().report_download(data, context=context, token=token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<odoo> | ||
<!-- | ||
© 2017 Creu Blanca | ||
License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). | ||
--> | ||
<record id="partner_xlsx" model="ir.actions.report"> | ||
<field name="name">Print to XLSX</field> | ||
<field name="model">res.partner</field> | ||
<field name="report_type">xlsx</field> | ||
<field name="report_name">report_xlsx.partner_xlsx</field> | ||
<field name="report_file">res_partner</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * report_xlsx | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 15.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"PO-Revision-Date: 2022-04-22 13:05+0000\n" | ||
"Last-Translator: pablontura <[email protected]>\n" | ||
"Language-Team: none\n" | ||
"Language: ca\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=2; plural=n != 1;\n" | ||
"X-Generator: Weblate 4.3.2\n" | ||
|
||
#. module: report_xlsx | ||
#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract | ||
msgid "Abstract XLSX Report" | ||
msgstr "Informe XLSX abstracte" | ||
|
||
#. module: report_xlsx | ||
#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx | ||
msgid "Partner XLSX Report" | ||
msgstr "Informe XLSX del soci" | ||
|
||
#. module: report_xlsx | ||
#: model:ir.actions.report,name:report_xlsx.partner_xlsx | ||
msgid "Print to XLSX" | ||
msgstr "Imprimeix a XLSX" | ||
|
||
#. module: report_xlsx | ||
#: model:ir.model,name:report_xlsx.model_ir_actions_report | ||
msgid "Report Action" | ||
msgstr "Informe d'acció" | ||
|
||
#. module: report_xlsx | ||
#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type | ||
msgid "Report Type" | ||
msgstr "Tipus d'informe" | ||
|
||
#. module: report_xlsx | ||
#: model:ir.model.fields,help:report_xlsx.field_ir_actions_report__report_type | ||
msgid "" | ||
"The type of the report that will be rendered, each one having its own " | ||
"rendering method. HTML means the report will be opened directly in your " | ||
"browser PDF means the report will be rendered using Wkhtmltopdf and " | ||
"downloaded by the user." | ||
msgstr "" | ||
"El tipus d'informe que es renderà, cadascun amb el seu propi mètode de " | ||
"representació. HTML significa que l'informe s'obrirà directament al vostre " | ||
"navegador, PDF significa que l'informe es representarà amb Wkhtmltopdf i " | ||
"l'usuari el baixarà." | ||
|
||
#. module: report_xlsx | ||
#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx | ||
msgid "XLSX" | ||
msgstr "XLSX" | ||
|
||
#, python-format | ||
#~ msgid "%s model was not found" | ||
#~ msgstr "No s'ha trobat el model %s" |
Oops, something went wrong.