diff --git a/.docker_files/main/__manifest__.py b/.docker_files/main/__manifest__.py index 83adafc..f854857 100644 --- a/.docker_files/main/__manifest__.py +++ b/.docker_files/main/__manifest__.py @@ -12,6 +12,7 @@ "summary": "Install all addons required for testing.", "depends": [ "report_aeroo", + "report_aeroo_replace_qweb" ], "installable": True, } diff --git a/Dockerfile b/Dockerfile index 3606ef1..51ce254 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ RUN pip3 install -r ./requirements.txt && rm ./requirements.txt USER odoo COPY ./report_aeroo /mnt/extra-addons/report_aeroo +COPY ./report_aeroo_replace_qweb /mnt/extra-addons/report_aeroo_replace_qweb COPY .docker_files/main /mnt/extra-addons/main COPY .docker_files/odoo.conf /etc/odoo diff --git a/report_aeroo_replace_qweb/README.rst b/report_aeroo_replace_qweb/README.rst new file mode 100644 index 0000000..4d3226b --- /dev/null +++ b/report_aeroo_replace_qweb/README.rst @@ -0,0 +1,43 @@ +========================= +Report Aeroo Replace Qweb +========================= + +.. contents:: Table of Contents + +Context +------- +Most Odoo applications come with a predefined set of Qweb reports. + +These reports are linked to 'PRINT' action buttons in form views and portal pages. + +.. image:: static/description/sale_order_print_button_before.png + +.. image:: static/description/sale_order_report_downloaded_before.png + +Summary +------- +This module allows to replace an existing Qweb report with an Aeroo report. + +Usage +----- +To do so, go to the form view of your aeroo report. + +Inside the Qweb tab, select the report to replace. + +.. image:: static/description/aeroo_report_qweb_tab.png + +Now, when printing the original report, the new aeroo report is printed instead. + +.. image:: static/description/sale_order_print_button_after.png + +.. image:: static/description/sale_order_report_downloaded_after.png + +Do not forget to add your aeroo report to the related email templates. + +.. image:: static/description/sale_order_email_template.png + +.. image:: static/description/sale_order_email_template_2.png + +More information +---------------- +* Meet us at https://bit.ly/numigi-com diff --git a/report_aeroo_replace_qweb/__init__.py b/report_aeroo_replace_qweb/__init__.py new file mode 100644 index 0000000..091a62e --- /dev/null +++ b/report_aeroo_replace_qweb/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import controllers, models diff --git a/report_aeroo_replace_qweb/__manifest__.py b/report_aeroo_replace_qweb/__manifest__.py new file mode 100644 index 0000000..506212d --- /dev/null +++ b/report_aeroo_replace_qweb/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +{ + "name": "Aeroo Reports Replace Qweb", + "version": "16.0.1.0.0", + "category": "Generic Modules/Aeroo Reports", + "summary": "Replace an aeroo report with a Qweb report", + "author": "Numigi", + "maintainer": "Numigi", + "website": "https://bit.ly/numigi-com", + "depends": ["report_aeroo"], + "data": [ + "views/ir_actions_report.xml", + ], + "license": "LGPL-3", + "installable": True, +} diff --git a/report_aeroo_replace_qweb/controllers/__init__.py b/report_aeroo_replace_qweb/controllers/__init__.py new file mode 100644 index 0000000..f35b322 --- /dev/null +++ b/report_aeroo_replace_qweb/controllers/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import main +from . import portal diff --git a/report_aeroo_replace_qweb/controllers/main.py b/report_aeroo_replace_qweb/controllers/main.py new file mode 100644 index 0000000..3a5d50a --- /dev/null +++ b/report_aeroo_replace_qweb/controllers/main.py @@ -0,0 +1,71 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License GPL-3.0 or later (http://www.gnu.org/licenses/gpl). + +import json +from odoo import http, models +from odoo.http import request +from odoo.addons.web.controllers.main import ReportController +from typing import List + + +class ReportControllerWithAerooReplacement(ReportController): + + @http.route(["/report/download"], type="http", auth="user") + def report_download(self, data, token): + """Dowload a replacement aeroo report instead of a qweb report. + + If the report is qweb-pdf and it has a replacement aeroo report, + the request is redirected to /web/report_aeroo. + + Without inheriting this method, the replacement report is printed, + but with the filename defined on the qweb report. + """ + requestcontent = json.loads(data) + url, type_ = requestcontent[0], requestcontent[1] + + if type_ == "qweb-pdf": + report = _get_report_from_qweb_download_url(url) + aeroo_report = report.aeroo_report_id + + if aeroo_report: + record_ids = _get_doc_ids_from_qweb_download_url(url) + return http.local_redirect( + "/web/report_aeroo", + { + "report_id": aeroo_report.id, + "record_ids": json.dumps(record_ids), + "token": token, + }, + ) + + return super().report_download(data, token) + + +def _get_report_from_qweb_download_url(url_: str) -> models.Model: + """Get the report object from the download URL of a qweb report. + + The url is expected to have the following format: + + /report/download/report_name/doc_ids?query_string + """ + report_name = url_.split("/")[3] + return request.env["ir.actions.report"]._get_report_from_name(report_name) + + +def _get_doc_ids_from_qweb_download_url(url_: str) -> List[int]: + """Get the report object from the download URL of a qweb report. + + The url is expected to have the following format: + + /report/download/report_name/doc_ids?query_string + + The parameter doc_ids inside the URL contains the ids of the + objects seperated by commas. + """ + url_parts = url_.split("/") + + if len(url_parts) < 5: + return [] + + ids_string = url_parts[4] + return [int(i) for i in ids_string.split(",")] diff --git a/report_aeroo_replace_qweb/controllers/portal.py b/report_aeroo_replace_qweb/controllers/portal.py new file mode 100644 index 0000000..278cd4b --- /dev/null +++ b/report_aeroo_replace_qweb/controllers/portal.py @@ -0,0 +1,23 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/gpl). + +from odoo.addons.portal.controllers.portal import CustomerPortal +from odoo.http import request + + +class PortalAccountWithAerooInvoiceReport(CustomerPortal): + + def _show_report(self, model, report_type, report_ref, download=False): + """Dowload a replacement aeroo report instead of a qweb report. + + Without inheriting this method, the replacement report is printed, + but with the filename defined on the qweb report. + """ + report = request.env.ref(report_ref) + report_id = report.sudo().aeroo_report_id + if report_type == "pdf" and report_id: + return self._show_aeroo_report(model, report_id, download=download) + else: + return super()._show_report( + model, report_type, report_ref, download=download + ) diff --git a/report_aeroo_replace_qweb/i18n/fr.po b/report_aeroo_replace_qweb/i18n/fr.po new file mode 100644 index 0000000..f9a1da5 --- /dev/null +++ b/report_aeroo_replace_qweb/i18n/fr.po @@ -0,0 +1,76 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_aeroo_replace_qweb +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-11-06 14:07+0000\n" +"PO-Revision-Date: 2024-11-06 14:07+0000\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_aeroo_replace_qweb +#: model:ir.model.fields,field_description:report_aeroo_replace_qweb.field_ir_actions_report__aeroo_report_id +msgid "Aeroo Report" +msgstr "" + +#. module: report_aeroo_replace_qweb +#: model_terms:ir.ui.view,arch_db:report_aeroo_replace_qweb.act_report_xml_view1 +msgid "For example, you may replace the standard Quotation / Order report." +msgstr "" +"Par exemple, vous pouvez remplacer le rapport Soumission / Commande de " +"l'application Ventes." + +#. module: report_aeroo_replace_qweb +#: model_terms:ir.ui.view,arch_db:report_aeroo_replace_qweb.act_report_xml_view1 +msgid "Qweb" +msgstr "" + +#. module: report_aeroo_replace_qweb +#: model:ir.model.fields,field_description:report_aeroo_replace_qweb.field_ir_actions_report__qweb_report_ids +msgid "Qweb Report" +msgstr "Rapport Qweb" + +#. module: report_aeroo_replace_qweb +#: model:ir.model,name:report_aeroo_replace_qweb.model_ir_actions_report +msgid "Report Action" +msgstr "Signaler l'action" + +#. module: report_aeroo_replace_qweb +#: model:ir.model.fields,help:report_aeroo_replace_qweb.field_ir_actions_report__qweb_report_ids +msgid "" +"This field allows to select Qweb reports that should be replaced by this " +"Aeroo report. Only qweb-pdf reports are supported." +msgstr "" +"Ce champ permet de sélectionner un(des) rapport(s) Qweb à remplacer par ce " +"rapport Aeroo. Seuls les rapports qweb-pdf sont supportés." + +#. module: report_aeroo_replace_qweb +#: model:ir.model.fields,help:report_aeroo_replace_qweb.field_ir_actions_report__aeroo_report_id +msgid "This field allows to select an Aeroo report that replaces this report." +msgstr "" +"Ce champ permet de sélectionner un rapport Aeroo qui remplace ce rapport." + +#. module: report_aeroo_replace_qweb +#: model_terms:ir.ui.view,arch_db:report_aeroo_replace_qweb.act_report_xml_view1 +msgid "" +"This tab allows to select Qweb reports that should be replaced by this Aeroo" +" report." +msgstr "" +"Cet onglet permet de sélectionner un(des) rapport Qweb à remplacer par ce " +"rapport Aeroo." + +#. module: report_aeroo_replace_qweb +#: model_terms:ir.ui.view,arch_db:report_aeroo_replace_qweb.act_report_xml_view1 +msgid "" +"When doing so, do not forget to adjust any related email template.\n" +" See the documentation of Aeroo reports for more details." +msgstr "" +"Ce faisant, n'oubliez pas d'ajuster tout modèle d'e-mail associé.\n" +" Consultez la documentation des rapports Aeroo pour plus de détails." diff --git a/report_aeroo_replace_qweb/models/__init__.py b/report_aeroo_replace_qweb/models/__init__.py new file mode 100644 index 0000000..acfd32b --- /dev/null +++ b/report_aeroo_replace_qweb/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from . import ir_actions_report diff --git a/report_aeroo_replace_qweb/models/ir_actions_report.py b/report_aeroo_replace_qweb/models/ir_actions_report.py new file mode 100644 index 0000000..e91c02e --- /dev/null +++ b/report_aeroo_replace_qweb/models/ir_actions_report.py @@ -0,0 +1,40 @@ +# Copyright 2024 Numigi (tm) and all its contributors (https://bit.ly/numigiens) +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). + +from odoo import fields, models + + +class IrActionsReport(models.Model): + """Allow replacing a qweb report with an aeroo report. + + In the form view of a qweb report, a many2one field allows to select + an aeroo report that replaces the qweb report. + + This allows to easily bind an aeroo report to the action buttons + of a form view. By default, most of those buttons are bound to a qweb report. + + This feature supports the qweb-pdf format but not qweb-html. + """ + + _inherit = "ir.actions.report" + + aeroo_report_id = fields.Many2one( + "ir.actions.report", + help="This field allows to select an Aeroo report that replaces this report.", + ) + + qweb_report_ids = fields.One2many( + "ir.actions.report", + "aeroo_report_id", + help="This field allows to select Qweb reports that should be replaced " + "by this Aeroo report. Only qweb-pdf reports are supported.", + ) + + def _render_qweb_pdf(self, report_ref, res_ids=None, data=None): + report_sudo = self._get_report(report_ref) + if report_sudo.aeroo_report_id: + return report_sudo.aeroo_report_id._render_aeroo( + doc_ids=res_ids, data=data, force_output_format="pdf" + ) + + return super()._render_qweb_pdf(report_ref, res_ids, data) diff --git a/report_aeroo_replace_qweb/static/description/aeroo_report_qweb_tab.png b/report_aeroo_replace_qweb/static/description/aeroo_report_qweb_tab.png new file mode 100644 index 0000000..6c008d1 Binary files /dev/null and b/report_aeroo_replace_qweb/static/description/aeroo_report_qweb_tab.png differ diff --git a/report_aeroo_replace_qweb/static/description/icon.png b/report_aeroo_replace_qweb/static/description/icon.png new file mode 100644 index 0000000..92a86b1 Binary files /dev/null and b/report_aeroo_replace_qweb/static/description/icon.png differ diff --git a/report_aeroo_replace_qweb/static/description/sale_order_email_template.png b/report_aeroo_replace_qweb/static/description/sale_order_email_template.png new file mode 100644 index 0000000..cb8de3a Binary files /dev/null and b/report_aeroo_replace_qweb/static/description/sale_order_email_template.png differ diff --git a/report_aeroo_replace_qweb/static/description/sale_order_email_template_2.png b/report_aeroo_replace_qweb/static/description/sale_order_email_template_2.png new file mode 100644 index 0000000..e2277b4 Binary files /dev/null and b/report_aeroo_replace_qweb/static/description/sale_order_email_template_2.png differ diff --git a/report_aeroo_replace_qweb/static/description/sale_order_print_button_after.png b/report_aeroo_replace_qweb/static/description/sale_order_print_button_after.png new file mode 100644 index 0000000..42336ce Binary files /dev/null and b/report_aeroo_replace_qweb/static/description/sale_order_print_button_after.png differ diff --git a/report_aeroo_replace_qweb/static/description/sale_order_print_button_before.png b/report_aeroo_replace_qweb/static/description/sale_order_print_button_before.png new file mode 100644 index 0000000..42336ce Binary files /dev/null and b/report_aeroo_replace_qweb/static/description/sale_order_print_button_before.png differ diff --git a/report_aeroo_replace_qweb/static/description/sale_order_report_downloaded_after.png b/report_aeroo_replace_qweb/static/description/sale_order_report_downloaded_after.png new file mode 100644 index 0000000..9dfcaf0 Binary files /dev/null and b/report_aeroo_replace_qweb/static/description/sale_order_report_downloaded_after.png differ diff --git a/report_aeroo_replace_qweb/static/description/sale_order_report_downloaded_before.png b/report_aeroo_replace_qweb/static/description/sale_order_report_downloaded_before.png new file mode 100644 index 0000000..1681b76 Binary files /dev/null and b/report_aeroo_replace_qweb/static/description/sale_order_report_downloaded_before.png differ diff --git a/report_aeroo_replace_qweb/views/ir_actions_report.xml b/report_aeroo_replace_qweb/views/ir_actions_report.xml new file mode 100644 index 0000000..2e1ac13 --- /dev/null +++ b/report_aeroo_replace_qweb/views/ir_actions_report.xml @@ -0,0 +1,46 @@ + + + + + Aeroo Report Form: add Qweb tab + ir.actions.report + + + + +
+

+ This tab allows to select Qweb reports that should be replaced by this Aeroo report. +

+

+ For example, you may replace the standard Quotation / Order report. +

+

+ When doing so, do not forget to adjust any related email template. + See the documentation of Aeroo reports for more details. +

+
+ +
+
+
+
+ + + Qweb Reports: add replacement Aeroo report + ir.actions.report + + + + + + + + +