diff --git a/report_xlsx/README.rst b/report_xlsx/README.rst new file mode 100644 index 0000000000..a2cbe1b9ad --- /dev/null +++ b/report_xlsx/README.rst @@ -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 `__ of +``xlsxwriter``. + +A report XML record : + +:: + + + Print to XLSX + res.partner + xlsx + module_name.report_name + module_name.report_file + + report + + + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV +* Creu Blanca + +Contributors +------------ + +- Adrien Peiffer +- Sébastien Alix +- Stéphane Bidoul +- Enric Tobella +- Graeme Gellatly +- Cristian Salamea +- Rod Schouteden +- Eugene Molotov +- Christopher Ormaza +- Houzéfa Abbasbhay +- Le Dinh Tien + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/report_xlsx/__init__.py b/report_xlsx/__init__.py new file mode 100644 index 0000000000..2a4823f861 --- /dev/null +++ b/report_xlsx/__init__.py @@ -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 diff --git a/report_xlsx/__manifest__.py b/report_xlsx/__manifest__.py new file mode 100644 index 0000000000..76b6c11e5d --- /dev/null +++ b/report_xlsx/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2015 ACSONE SA/NV () +# 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", + ], + }, +} diff --git a/report_xlsx/controllers/__init__.py b/report_xlsx/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/report_xlsx/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/report_xlsx/controllers/main.py b/report_xlsx/controllers/main.py new file mode 100644 index 0000000000..4b11c003a4 --- /dev/null +++ b/report_xlsx/controllers/main.py @@ -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) diff --git a/report_xlsx/demo/report.xml b/report_xlsx/demo/report.xml new file mode 100644 index 0000000000..e269404713 --- /dev/null +++ b/report_xlsx/demo/report.xml @@ -0,0 +1,14 @@ + + + + + Print to XLSX + res.partner + xlsx + report_xlsx.partner_xlsx + res_partner + + diff --git a/report_xlsx/i18n/ca.po b/report_xlsx/i18n/ca.po new file mode 100644 index 0000000000..f1c20a966d --- /dev/null +++ b/report_xlsx/i18n/ca.po @@ -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 \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" diff --git a/report_xlsx/i18n/de.po b/report_xlsx/i18n/de.po new file mode 100644 index 0000000000..0e9a8c60ca --- /dev/null +++ b/report_xlsx/i18n/de.po @@ -0,0 +1,107 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# Ricardo Gross , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-23 03:49+0000\n" +"PO-Revision-Date: 2019-07-12 12:43+0000\n" +"Last-Translator: Maria Sparenberg \n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"Language: de\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 3.7.1\n" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "Abstrakter XLSX-Bericht" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +#, fuzzy +msgid "Partner XLSX Report" +msgstr "Abstrakter XLSX-Bericht" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "Drucke nach XLSX" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "Berichtsaktion" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "Berichtsart" + +#. 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 "" +"Die Art des Berichts, der erstellt wird, jeder mit eigener Darstellungsform. " +"HTML bedeutet, dass der Bericht unmittelbar in Ihrem Browser dargestellt " +"wird, PDF bedeutet, dass der Bericht mittels Wkhtmltopdf gewandelt wird und " +"vom Anwender heruntergeladen wird." + +#. 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 "%s Modell wurde nicht gefunden" + +#, python-format +#~ msgid "" +#~ "A popup window with your report was blocked. You may need to change your " +#~ "browser settings to allow popup windows for this page." +#~ msgstr "" +#~ "Ein Popup-Fenster wurde abgewiesen. Sie werden vermutlich Ihre Browser-" +#~ "Einstellungen ändern müssen, damit die Anzeige dieser Seite möglich wird." + +#~ msgid "Display Name" +#~ msgstr "Name anzeigen" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Zuletzt geändert am" + +#, python-format +#~ msgid "Warning" +#~ msgstr "Hinweis" + +#~ msgid "HTML" +#~ msgstr "HTML" + +#~ msgid "PDF" +#~ msgstr "PDF" + +#~ msgid "Py3o" +#~ msgstr "Py3o" + +#~ msgid "Text" +#~ msgstr "Text" + +#~ msgid "XML" +#~ msgstr "XML" + +#~ msgid "report.report_xlsx.partner_xlsx" +#~ msgstr "report.report_xlsx.partner_xlsx" diff --git a/report_xlsx/i18n/es.po b/report_xlsx/i18n/es.po new file mode 100644 index 0000000000..1f28ba30c8 --- /dev/null +++ b/report_xlsx/i18n/es.po @@ -0,0 +1,93 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# Pedro M. Baeza , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-11-01 20:11+0000\n" +"PO-Revision-Date: 2023-09-02 20:42+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\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.17\n" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "Informe XLSX en abstracto" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "Informe empresa XLSX" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "Imprimir en XLSX" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "Informar Acción" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "Tipo 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 tipo de informe que se representará, cada uno con su propio método de " +"representación. HTML significa que el informe se abrirá directamente en el " +"PDF de su navegador significa que el informe se representará usando " +"Wkhtmltopdf y el usuario lo descargará." + +#. 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 "%s modelo no fue encontrado" + +#, python-format +#~ msgid "" +#~ "A popup window with your report was blocked. You may need to change your " +#~ "browser settings to allow popup windows for this page." +#~ msgstr "" +#~ "Una ventana emergente con su informe fue bloqueada. Puede que necesite " +#~ "cambiar las preferencias de su navegador para que permita ventanas " +#~ "emergentes en esta página." + +#~ msgid "Display Name" +#~ msgstr "Nombre mostrado" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última modificación el" + +#, python-format +#~ msgid "Warning" +#~ msgstr "Aviso" + +#, fuzzy +#~ msgid "ir.actions.report" +#~ msgstr "ir.actions.report.xml" diff --git a/report_xlsx/i18n/fr.po b/report_xlsx/i18n/fr.po new file mode 100644 index 0000000000..148ebbd408 --- /dev/null +++ b/report_xlsx/i18n/fr.po @@ -0,0 +1,80 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# Nicolas JEUDY , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-05 17:53+0000\n" +"PO-Revision-Date: 2018-01-05 17:53+0000\n" +"Last-Translator: Nicolas JEUDY , 2018\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\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" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "Imprimer en XLSX" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "" + +#. 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 "" + +#. module: report_xlsx +#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx +msgid "XLSX" +msgstr "" + +#, python-format +#~ msgid "%s model was not found" +#~ msgstr "model '%s' n'a pas été trouvé" + +#~ msgid "Display Name" +#~ msgstr "Nom" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Dernière modification le" + +#~ msgid "report.report_xlsx.partner_xlsx" +#~ msgstr "report.report_xlsx.partner_xlsx" + +#~ msgid "ir.actions.report" +#~ msgstr "ir.actions.report" + +#~ msgid "report.report_xlsx.abstract" +#~ msgstr "report.report_xlsx.abstract" diff --git a/report_xlsx/i18n/hr.po b/report_xlsx/i18n/hr.po new file mode 100644 index 0000000000..e573e87f42 --- /dev/null +++ b/report_xlsx/i18n/hr.po @@ -0,0 +1,79 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-05-31 03:52+0000\n" +"PO-Revision-Date: 2023-01-04 03:24+0000\n" +"Last-Translator: Bole \n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "" + +#. 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 "" + +#. module: report_xlsx +#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx +msgid "XLSX" +msgstr "" + +#, python-format +#~ msgid "%s model was not found" +#~ msgstr "%s model nije pronađen" + +#, python-format +#~ msgid "" +#~ "A popup window with your report was blocked. You may need to change your " +#~ "browser settings to allow popup windows for this page." +#~ msgstr "" +#~ "Skočni prozor sa vašim izvještajem je blokiran. Možda trebate promijeniti " +#~ "postavke pretraživača da dozvolite skočne prozore za ovu stranicu." + +#~ msgid "Display Name" +#~ msgstr "Naziv za prikaz" + +#, fuzzy +#~ msgid "ir.actions.report" +#~ msgstr "ir.actions.report.xml" diff --git a/report_xlsx/i18n/hr_HR.po b/report_xlsx/i18n/hr_HR.po new file mode 100644 index 0000000000..a991e6eb50 --- /dev/null +++ b/report_xlsx/i18n/hr_HR.po @@ -0,0 +1,64 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# Bole , 2016 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-11-01 20:11+0000\n" +"PO-Revision-Date: 2016-11-01 20:11+0000\n" +"Last-Translator: Bole , 2016\n" +"Language-Team: Croatian (Croatia) (https://www.transifex.com/oca/teams/23907/" +"hr_HR/)\n" +"Language: hr_HR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "" + +#. 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 "" + +#. module: report_xlsx +#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx +msgid "XLSX" +msgstr "" + +#, fuzzy +#~ msgid "ir.actions.report" +#~ msgstr "ir.actions.report.xml" diff --git a/report_xlsx/i18n/it.po b/report_xlsx/i18n/it.po new file mode 100644 index 0000000000..e2bd67bcae --- /dev/null +++ b/report_xlsx/i18n/it.po @@ -0,0 +1,67 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-05-31 03:52+0000\n" +"PO-Revision-Date: 2024-02-12 10:46+0000\n" +"Last-Translator: mymage \n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"Language: it\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.17\n" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "Report XLSX astratto" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "Resoconto XLSX partner" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "Stampa su XLSX" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "Azione resoconto" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "Tipo resoconto" + +#. 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 "" +"Il tipo di resoconto che verrà generato, ognuno avente il suo metodo di " +"generazione. HTML vuol dire che il resoconto sarà aperto direttamente nel " +"tuo browser mentre PDF vuol dire che il resoconto sarà generato usando " +"Wkhtmltopdf e scaricato dall'utente." + +#. module: report_xlsx +#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx +msgid "XLSX" +msgstr "XLSX" + +#, fuzzy +#~ msgid "ir.actions.report" +#~ msgstr "ir.actions.report.xml" diff --git a/report_xlsx/i18n/nl_NL.po b/report_xlsx/i18n/nl_NL.po new file mode 100644 index 0000000000..7cb04e7f55 --- /dev/null +++ b/report_xlsx/i18n/nl_NL.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# Peter Hageman , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-06-23 00:28+0000\n" +"PO-Revision-Date: 2017-06-23 00:28+0000\n" +"Last-Translator: Peter Hageman , 2017\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/" +"teams/23907/nl_NL/)\n" +"Language: nl_NL\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" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "" + +#. 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 "" + +#. module: report_xlsx +#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx +msgid "XLSX" +msgstr "" + +#, fuzzy +#~ msgid "ir.actions.report" +#~ msgstr "ir.actions.report.xml" diff --git a/report_xlsx/i18n/pt.po b/report_xlsx/i18n/pt.po new file mode 100644 index 0000000000..ea7399ea6f --- /dev/null +++ b/report_xlsx/i18n/pt.po @@ -0,0 +1,101 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-07-02 23:48+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\n" +"Language: pt\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 "Relatório XLSX Abstrato" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "Relatório de Parceiro XLSX" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "Imprimir para XLSX" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "Ação do Relatório" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "Tipo de Relatório" + +#. 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 "" +"O tipo de relatório que será produzido, tendo cada qual o seu método de " +"produção. HTML significa que o relatório será aberto diretamente no seu " +"browser. PDF indica que o relatório será produzido com o Wkhtmltopdf e " +"descarregado pelo utilizador." + +#. 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 "O modelo %s não foi encontrado" + +#, python-format +#~ msgid "" +#~ "A popup window with your report was blocked. You may need to change your " +#~ "browser settings to allow popup windows for this page." +#~ msgstr "" +#~ "Uma janela popup com o seu relatório foi bloqueada. Pode necessitar de " +#~ "mudar as configurações do browser para permitir janelas popup nesta " +#~ "página." + +#~ msgid "Display Name" +#~ msgstr "Nome a Exibir" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Última Modificação em" + +#, python-format +#~ msgid "Warning" +#~ msgstr "Aviso" + +#~ msgid "HTML" +#~ msgstr "HTML" + +#~ msgid "PDF" +#~ msgstr "PDF" + +#~ msgid "Py3o" +#~ msgstr "Py3o" + +#~ msgid "Text" +#~ msgstr "Texto" + +#~ msgid "XML" +#~ msgstr "XML" diff --git a/report_xlsx/i18n/pt_PT.po b/report_xlsx/i18n/pt_PT.po new file mode 100644 index 0000000000..41323eaf3b --- /dev/null +++ b/report_xlsx/i18n/pt_PT.po @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-05-31 03:52+0000\n" +"PO-Revision-Date: 2017-05-31 03:52+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Portuguese (Portugal) (https://www.transifex.com/oca/" +"teams/23907/pt_PT/)\n" +"Language: pt_PT\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" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "" + +#. 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 "" + +#. module: report_xlsx +#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx +msgid "XLSX" +msgstr "" + +#, fuzzy +#~ msgid "ir.actions.report" +#~ msgstr "ir.actions.report.xml" diff --git a/report_xlsx/i18n/report_xlsx.pot b/report_xlsx/i18n/report_xlsx.pot new file mode 100644 index 0000000000..339a5610c9 --- /dev/null +++ b/report_xlsx/i18n/report_xlsx.pot @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "" + +#. 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 "" + +#. module: report_xlsx +#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx +msgid "XLSX" +msgstr "" diff --git a/report_xlsx/i18n/sv.po b/report_xlsx/i18n/sv.po new file mode 100644 index 0000000000..058ed3d423 --- /dev/null +++ b/report_xlsx/i18n/sv.po @@ -0,0 +1,85 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-06-12 08:55+0000\n" +"Last-Translator: jakobkrabbe \n" +"Language-Team: none\n" +"Language: sv\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.17\n" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "Abstrakt XLSX-rapport" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "Partner XLSX-rapport" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "Skriv ut till XLSX" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "Rapportåtgärd" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "Rapporttyp" + +#. 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 "" +"Den typ av rapport som ska renderas, var och en har sin egen " +"renderingsmetod. HTML innebär att rapporten öppnas direkt i webbläsaren, PDF " +"betyder att rapporten renderas med Wkhtmltopdf och laddas ner av användaren." + +#. 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 "%s modell hittades inte" + +#, python-format +#~ msgid "" +#~ "A popup window with your report was blocked. You may need to change your " +#~ "browser settings to allow popup windows for this page." +#~ msgstr "" +#~ "Ett popup-fönster med din rapport blockerades. Du kan behöva ändra " +#~ "inställningarna i din webbläsare för att tillåta popup-fönster på den här " +#~ "sidan." + +#~ msgid "Display Name" +#~ msgstr "Visningsnamn" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Senast ändrad den" + +#, python-format +#~ msgid "Warning" +#~ msgstr "Varning" diff --git a/report_xlsx/i18n/tr.po b/report_xlsx/i18n/tr.po new file mode 100644 index 0000000000..bb2cfe3c0c --- /dev/null +++ b/report_xlsx/i18n/tr.po @@ -0,0 +1,62 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_xlsx +# +# Translators: +# OCA Transbot , 2017 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-05-31 03:52+0000\n" +"PO-Revision-Date: 2017-05-31 03:52+0000\n" +"Last-Translator: OCA Transbot , 2017\n" +"Language-Team: Turkish (https://www.transifex.com/oca/teams/23907/tr/)\n" +"Language: tr\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" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_abstract +msgid "Abstract XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_report_report_xlsx_partner_xlsx +msgid "Partner XLSX Report" +msgstr "" + +#. module: report_xlsx +#: model:ir.actions.report,name:report_xlsx.partner_xlsx +msgid "Print to XLSX" +msgstr "" + +#. module: report_xlsx +#: model:ir.model,name:report_xlsx.model_ir_actions_report +msgid "Report Action" +msgstr "" + +#. module: report_xlsx +#: model:ir.model.fields,field_description:report_xlsx.field_ir_actions_report__report_type +msgid "Report Type" +msgstr "" + +#. 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 "" + +#. module: report_xlsx +#: model:ir.model.fields.selection,name:report_xlsx.selection__ir_actions_report__report_type__xlsx +msgid "XLSX" +msgstr "" + +#, fuzzy +#~ msgid "ir.actions.report" +#~ msgstr "ir.actions.report.xml" diff --git a/report_xlsx/models/__init__.py b/report_xlsx/models/__init__.py new file mode 100644 index 0000000000..54dbf3df6e --- /dev/null +++ b/report_xlsx/models/__init__.py @@ -0,0 +1 @@ +from . import ir_report diff --git a/report_xlsx/models/ir_report.py b/report_xlsx/models/ir_report.py new file mode 100644 index 0000000000..bf61546f25 --- /dev/null +++ b/report_xlsx/models/ir_report.py @@ -0,0 +1,79 @@ +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import logging + +from odoo import api, exceptions, fields, models +from odoo.tools.safe_eval import safe_eval, time + +_logger = logging.getLogger(__name__) + + +class ReportAction(models.Model): + _inherit = "ir.actions.report" + + report_type = fields.Selection( + selection_add=[("xlsx", "XLSX")], ondelete={"xlsx": "set default"} + ) + + @api.model + def _render_xlsx(self, report_ref, docids, data): + report_sudo = self._get_report(report_ref) + report_model_name = f"report.{report_sudo.report_name}" + report_model = self.env[report_model_name] + ret = ( + report_model.with_context(active_model=report_sudo.model) + .sudo(False) + .create_xlsx_report(docids, data) # noqa + ) + if ret and isinstance(ret, (tuple | list)): # data, "xlsx" + report_sudo.save_xlsx_report_attachment(docids, ret[0]) + return ret + + @api.model + def _get_report_from_name(self, report_name): + res = super()._get_report_from_name(report_name) + if res: + return res + report_obj = self.env["ir.actions.report"] + qwebtypes = ["xlsx"] + conditions = [ + ("report_type", "in", qwebtypes), + ("report_name", "=", report_name), + ] + context = self.env["res.users"].context_get() + return report_obj.with_context(**context).search(conditions, limit=1) + + def save_xlsx_report_attachment(self, docids, report_contents): + """Save as attachment when the report is set up as such.""" + # Similar to ir.actions.report::_render_qweb_pdf in the base module. + if not self.attachment: + return + if len(docids) != 1: # unlike PDFs, here we don't have multiple streams + _logger.warning(f"{self.name}: No records to save attachments onto.") + return + record = self.env[self.model].browse(docids) + attachment_name = safe_eval(self.attachment, {"object": record, "time": time}) + if not attachment_name: + return # same as for PDFs, get out silently when name fails + attachment_values = { + "name": attachment_name, + "raw": report_contents, + "res_id": record.id, + "res_model": self.model, + "type": "binary", + } + try: + attachment = self.env["ir.attachment"].create(attachment_values) + except exceptions.AccessError: + _logger.info( + "Cannot save XLSX report %r attachment for user %r", + attachment_values["name"], + self.env.user.display_name, + ) + else: + _logger.info( + "The XLSX document %r is now saved in the database", + attachment_values["name"], + ) + return attachment, record diff --git a/report_xlsx/pyproject.toml b/report_xlsx/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/report_xlsx/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/report_xlsx/readme/CONTRIBUTORS.md b/report_xlsx/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..db39b2e523 --- /dev/null +++ b/report_xlsx/readme/CONTRIBUTORS.md @@ -0,0 +1,11 @@ +- Adrien Peiffer \<\> +- Sébastien Alix \<\> +- Stéphane Bidoul \<\> +- Enric Tobella \<\> +- Graeme Gellatly \<\> +- Cristian Salamea \<\> +- Rod Schouteden \<\> +- Eugene Molotov \<\> +- Christopher Ormaza \<\> +- Houzéfa Abbasbhay \<\> +- Le Dinh Tien \<\> diff --git a/report_xlsx/readme/DESCRIPTION.md b/report_xlsx/readme/DESCRIPTION.md new file mode 100644 index 0000000000..894b124637 --- /dev/null +++ b/report_xlsx/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module provides a basic report class to generate xlsx report. diff --git a/report_xlsx/readme/INSTALL.md b/report_xlsx/readme/INSTALL.md new file mode 100644 index 0000000000..013e317970 --- /dev/null +++ b/report_xlsx/readme/INSTALL.md @@ -0,0 +1,7 @@ +Make sure you have `xlsxwriter` Python module installed: + + $ pip3 install xlsxwriter + +For testing it is also necessary `xlrd` Python module installed: + + $ pip3 install xlrd diff --git a/report_xlsx/readme/USAGE.md b/report_xlsx/readme/USAGE.md new file mode 100644 index 0000000000..d869a5e3e2 --- /dev/null +++ b/report_xlsx/readme/USAGE.md @@ -0,0 +1,34 @@ +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 : + + + Print to XLSX + res.partner + xlsx + module_name.report_name + module_name.report_file + + report + + diff --git a/report_xlsx/report/__init__.py b/report_xlsx/report/__init__.py new file mode 100644 index 0000000000..9e899a9fc2 --- /dev/null +++ b/report_xlsx/report/__init__.py @@ -0,0 +1,2 @@ +from . import report_abstract_xlsx +from . import report_partner_xlsx diff --git a/report_xlsx/report/report_abstract_xlsx.py b/report_xlsx/report/report_abstract_xlsx.py new file mode 100644 index 0000000000..bbad65ad1e --- /dev/null +++ b/report_xlsx/report/report_abstract_xlsx.py @@ -0,0 +1,118 @@ +# Copyright 2015 ACSONE SA/NV () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import logging +import re +from io import BytesIO + +from odoo import models + +_logger = logging.getLogger(__name__) + +try: + import xlsxwriter + + class PatchedXlsxWorkbook(xlsxwriter.Workbook): + def _check_sheetname(self, sheetname, is_chartsheet=False): + """We want to avoid duplicated sheet names exceptions the same following + the same philosophy that Odoo implements overriding the main library + to avoid the 31 characters limit triming the strings before sending them + to the library. + + In some cases, there's not much control over this as the reports send + automated data and the potential exception is hidden underneath making it + hard to debug the original issue. Even so, different names can become the + same one as their strings are trimmed to those 31 character limit. + + This way, once we come across with a duplicated, we set that final 3 + characters with a sequence that we evaluate on the fly. So for instance: + + - 'Sheet name' will be 'Sheet name~01' + - The next 'Sheet name' will try to rename to 'Sheet name~01' as well and + then that will give us 'Sheet name~02'. + - And the next 'Sheet name' will try to rename to 'Sheet name~01' and then + to 'Sheet name~02' and finally it will be able to 'Sheet name~03'. + - An so on as many times as duplicated sheet names come to the workbook up + to 100 for each sheet name. We set such limit as we don't want to truncate + the strings too much and keeping in mind that this issue don't usually + ocurrs. + """ + try: + return super()._check_sheetname(sheetname, is_chartsheet=is_chartsheet) + except xlsxwriter.exceptions.DuplicateWorksheetName: + pattern = re.compile(r"~[0-9]{2}$") + duplicated_secuence = ( + re.search(pattern, sheetname) and int(sheetname[-2:]) or 0 + ) + # Only up to 100 duplicates + deduplicated_secuence = f"~{duplicated_secuence + 1:02d}" + if duplicated_secuence > 99: + raise xlsxwriter.exceptions.DuplicateWorksheetName # noqa: B904 + if duplicated_secuence: + sheetname = re.sub(pattern, deduplicated_secuence, sheetname) + elif len(sheetname) <= 28: + sheetname += deduplicated_secuence + else: + sheetname = sheetname[:28] + deduplicated_secuence + # Refeed the method until we get an unduplicated name + return self._check_sheetname(sheetname, is_chartsheet=is_chartsheet) + + # "Short string" + + xlsxwriter.Workbook = PatchedXlsxWorkbook + +except ImportError: + _logger.debug("Can not import xlsxwriter`.") + + +class ReportXlsxAbstract(models.AbstractModel): + _name = "report.report_xlsx.abstract" + _description = "Abstract XLSX Report" + + def _get_objs_for_report(self, docids, data): + """ + Returns objects for xlx report. From WebUI these + are either as docids taken from context.active_ids or + in the case of wizard are in data. Manual calls may rely + on regular context, setting docids, or setting data. + + :param docids: list of integers, typically provided by + qwebactionmanager for regular Models. + :param data: dictionary of data, if present typically provided + by qwebactionmanager for TransientModels. + :param ids: list of integers, provided by overrides. + :return: recordset of active model for ids. + """ + if docids: + ids = docids + elif data and "context" in data: + ids = data["context"].get("active_ids", []) + else: + ids = self.env.context.get("active_ids", []) + return self.env[self.env.context.get("active_model")].browse(ids) + + def _report_xlsx_currency_format(self, currency): + """Get the format to be used in cells (symbol included). + Used in account_financial_report addon""" + s_before = currency.symbol if currency.position == "before" else "" + s_after = f" {currency.symbol}" if currency.position == "after" else "" + return f"{f'{s_before}'}#,##0.{'0' * currency.decimal_places}{f'{s_after}'}" + + def create_xlsx_report(self, docids, data): + objs = self._get_objs_for_report(docids, data) + file_data = BytesIO() + workbook = xlsxwriter.Workbook(file_data, self.get_workbook_options()) + self.generate_xlsx_report(workbook, data, objs) + workbook.close() + file_data.seek(0) + return file_data.read(), "xlsx" + + def get_workbook_options(self): + """ + See https://xlsxwriter.readthedocs.io/workbook.html constructor options + :return: A dictionary of options + """ + return {} + + def generate_xlsx_report(self, workbook, data, objs): + raise NotImplementedError() diff --git a/report_xlsx/report/report_partner_xlsx.py b/report_xlsx/report/report_partner_xlsx.py new file mode 100644 index 0000000000..558c6a0417 --- /dev/null +++ b/report_xlsx/report/report_partner_xlsx.py @@ -0,0 +1,16 @@ +# Copyright 2017 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class PartnerXlsx(models.AbstractModel): + _name = "report.report_xlsx.partner_xlsx" + _inherit = "report.report_xlsx.abstract" + _description = "Partner XLSX Report" + + def generate_xlsx_report(self, workbook, data, partners): + sheet = workbook.add_worksheet("Report") + for i, obj in enumerate(partners): + bold = workbook.add_format({"bold": True}) + sheet.write(i, 0, obj.name, bold) diff --git a/report_xlsx/static/description/icon.png b/report_xlsx/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/report_xlsx/static/description/icon.png differ diff --git a/report_xlsx/static/description/index.html b/report_xlsx/static/description/index.html new file mode 100644 index 0000000000..153de94f8c --- /dev/null +++ b/report_xlsx/static/description/index.html @@ -0,0 +1,484 @@ + + + + + +Base report xlsx + + + +
+

Base report xlsx

+ + +

Mature License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runboat

+

This module provides a basic report class to generate xlsx report.

+

Table of contents

+ +
+

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 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. +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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
  • Creu Blanca
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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 project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/report_xlsx/static/src/js/report/action_manager_report.esm.js b/report_xlsx/static/src/js/report/action_manager_report.esm.js new file mode 100644 index 0000000000..dd85ed84e8 --- /dev/null +++ b/report_xlsx/static/src/js/report/action_manager_report.esm.js @@ -0,0 +1,51 @@ +import {download} from "@web/core/network/download"; +import {registry} from "@web/core/registry"; +import {user} from "@web/core/user"; + +registry + .category("ir.actions.report handlers") + .add("xlsx_handler", async function (action, options, env) { + if (action.report_type === "xlsx") { + const type = action.report_type; + let url = `/report/${type}/${action.report_name}`; + const actionContext = action.context || {}; + if (action.data && JSON.stringify(action.data) !== "{}") { + // Build a query string with `action.data` (it's the place where reports + // using a wizard to customize the output traditionally put their options) + const action_options = encodeURIComponent(JSON.stringify(action.data)); + const context = encodeURIComponent(JSON.stringify(actionContext)); + url += `?options=${action_options}&context=${context}`; + } else { + if (actionContext.active_ids) { + url += `/${actionContext.active_ids.join(",")}`; + } + if (type === "xlsx") { + const context = encodeURIComponent(JSON.stringify(user.context)); + url += `?context=${context}`; + } + } + env.services.ui.block(); + try { + await download({ + url: "/report/download", + data: { + data: JSON.stringify([url, action.report_type]), + context: JSON.stringify(user.context), + }, + }); + } finally { + env.services.ui.unblock(); + } + const onClose = options.onClose; + if (action.close_on_report_download) { + return env.services.action.doAction( + {type: "ir.actions.act_window_close"}, + {onClose} + ); + } else if (onClose) { + onClose(); + } + return Promise.resolve(true); + } + return Promise.resolve(false); + }); diff --git a/report_xlsx/tests/__init__.py b/report_xlsx/tests/__init__.py new file mode 100644 index 0000000000..32ae3c2c34 --- /dev/null +++ b/report_xlsx/tests/__init__.py @@ -0,0 +1 @@ +from . import test_report diff --git a/report_xlsx/tests/test_report.py b/report_xlsx/tests/test_report.py new file mode 100644 index 0000000000..d91383ac1f --- /dev/null +++ b/report_xlsx/tests/test_report.py @@ -0,0 +1,75 @@ +# Copyright 2017 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import logging + +from odoo.tests import common + +_logger = logging.getLogger(__name__) + +try: + from xlrd import open_workbook +except ImportError: + _logger.debug("Can not import xlrd`.") + + +class TestReport(common.TransactionCase): + def setUp(self): + super().setUp() + self.report_object = self.env["ir.actions.report"] + self.xlsx_report = self.env["report.report_xlsx.abstract"].with_context( + active_model="res.partner" + ) + self.report_name = "report_xlsx.partner_xlsx" + self.report = self.report_object._get_report_from_name(self.report_name) + self.docs = self.env["res.company"].search([], limit=1).partner_id + + def test_report(self): + report = self.report + self.assertEqual(report.report_type, "xlsx") + rep = self.report_object._render(self.report_name, self.docs.ids, {}) + wb = open_workbook(file_contents=rep[0]) + sheet = wb.sheet_by_index(0) + self.assertEqual(sheet.cell(0, 0).value, self.docs.name) + + def test_save_attachment(self): + self.report.attachment = 'object.name + ".xlsx"' + self.report_object._render(self.report_name, self.docs.ids, {}) + attachment = self.env["ir.attachment"].search( + [("res_id", "=", self.docs.id), ("res_model", "=", self.docs._name)] + ) + self.assertEqual(len(attachment), 1) + self.assertEqual(attachment.name, f"{self.docs.name}.xlsx") + + def test_id_retrieval(self): + # Typical call from WebUI with wizard + objs = self.xlsx_report._get_objs_for_report( + False, {"context": {"active_ids": self.docs.ids}} + ) + self.assertEqual(objs, self.docs) + + # Typical call from within code not to report_action + objs = self.xlsx_report.with_context( + active_ids=self.docs.ids + )._get_objs_for_report(False, False) + self.assertEqual(objs, self.docs) + + # Typical call from WebUI + objs = self.xlsx_report._get_objs_for_report( + self.docs.ids, {"data": [self.report_name, self.report.report_type]} + ) + self.assertEqual(objs, self.docs) + + # Typical call from render + objs = self.xlsx_report._get_objs_for_report(self.docs.ids, {}) + self.assertEqual(objs, self.docs) + + def test_currency_format(self): + usd = self.env.ref("base.USD") + self.assertEqual( + self.xlsx_report._report_xlsx_currency_format(usd), "$#,##0.00" + ) + eur = self.env.ref("base.EUR") + self.assertEqual( + self.xlsx_report._report_xlsx_currency_format(eur), "#,##0.00 €" + ) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000..c208f5bc3f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +# generated from manifests external_dependencies +xlrd +xlsxwriter