Skip to content

Commit

Permalink
[16.0][MIG] report_aeroo_replace_qweb (#68)
Browse files Browse the repository at this point in the history
Co-authored-by: Majda EL MARIOULI <[email protected]>
  • Loading branch information
rivo2302 and majouda authored Nov 7, 2024
1 parent 88b2996 commit 7edd71a
Show file tree
Hide file tree
Showing 20 changed files with 332 additions and 0 deletions.
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"summary": "Install all addons required for testing.",
"depends": [
"report_aeroo",
"report_aeroo_replace_qweb"
],
"installable": True,
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions report_aeroo_replace_qweb/README.rst
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions report_aeroo_replace_qweb/__init__.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions report_aeroo_replace_qweb/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
5 changes: 5 additions & 0 deletions report_aeroo_replace_qweb/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -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
71 changes: 71 additions & 0 deletions report_aeroo_replace_qweb/controllers/main.py
Original file line number Diff line number Diff line change
@@ -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(",")]
23 changes: 23 additions & 0 deletions report_aeroo_replace_qweb/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -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
)
76 changes: 76 additions & 0 deletions report_aeroo_replace_qweb/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -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."
4 changes: 4 additions & 0 deletions report_aeroo_replace_qweb/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions report_aeroo_replace_qweb/models/ir_actions_report.py
Original file line number Diff line number Diff line change
@@ -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)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions report_aeroo_replace_qweb/views/ir_actions_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="act_report_xml_view1" model="ir.ui.view">
<field name="name">Aeroo Report Form: add Qweb tab</field>
<field name="model">ir.actions.report</field>
<field name="inherit_id" ref="report_aeroo.act_report_xml_view1" />
<field name="arch" type="xml">
<notebook position="inside">
<page string="Qweb">
<div>
<p>
This tab allows to select Qweb reports that should be replaced by this Aeroo report.
</p>
<p>
For example, you may replace the standard Quotation / Order report.
</p>
<p>
When doing so, do not forget to adjust any related email template.
See the documentation of Aeroo reports for more details.
</p>
</div>
<field name="qweb_report_ids"
domain="[('model', '=', model), ('report_type', '=', 'qweb-pdf')]"
widget="many2many"
/>
</page>
</notebook>
</field>
</record>

<record id="qweb_report_form_with_aeroo_replacement" model="ir.ui.view">
<field name="name">Qweb Reports: add replacement Aeroo report</field>
<field name="model">ir.actions.report</field>
<field name="inherit_id" ref="base.act_report_xml_view" />
<field name="arch" type="xml">
<field name="paperformat_id" position="after">
<field name="aeroo_report_id"
domain="[('model', '=', model), ('report_type', '=', 'aeroo')]"
attrs="{'invisible': [('report_type', '!=', 'qweb-pdf')]}"
/>
</field>
</field>
</record>

</odoo>

0 comments on commit 7edd71a

Please sign in to comment.