Skip to content

Commit

Permalink
TA#67306 [16.0] [MIG] report_aeroo_invoice (#71)
Browse files Browse the repository at this point in the history
* [16.0][MIG] report_aeroo_invoice
  • Loading branch information
rivo2302 authored Nov 15, 2024
1 parent 859118e commit 5c17236
Show file tree
Hide file tree
Showing 19 changed files with 357 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 @@ -13,6 +13,7 @@
"depends": [
"account_check_printing_aeroo",
"report_aeroo",
"report_aeroo_invoice",
"report_aeroo_replace_qweb",
],
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ USER odoo

COPY ./account_check_printing_aeroo /mnt/extra-addons/account_check_printing_aeroo
COPY ./report_aeroo /mnt/extra-addons/report_aeroo
COPY ./report_aeroo_invoice /mnt/extra-addons/report_aeroo_invoice
COPY ./report_aeroo_replace_qweb /mnt/extra-addons/report_aeroo_replace_qweb

COPY .docker_files/main /mnt/extra-addons/main
Expand Down
30 changes: 30 additions & 0 deletions report_aeroo_invoice/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
====================
Report Aeroo Invoice
====================
This module allows printing a customer invoice using Aeroo reports.

It defines an aeroo template as the main template for printing invoices.


Print Button On Invoice Form
----------------------------
The `Print` button on the customer invoice form allows to print the qweb invoice.

This module changes the behavior of the button to print an aeroo report instead.

Download Button On Portal
-------------------------
The dowload link on the portal is hardcoded to print a qweb report.

This module changes the behavior of the button to print an aeroo report instead.

Configuration
-------------
To set the main Aeroo invoice template:

* Go to `Accounting / Configuration / Configuration`.
* In the `Invoices` section, select the template in the field `Customer Invoice Aeroo Template`.

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
5 changes: 5 additions & 0 deletions report_aeroo_invoice/__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 controllers
from . import models
30 changes: 30 additions & 0 deletions report_aeroo_invoice/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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": "Report Aeroo Invoice",
"version": "16.0.1.0.0",
"category": "Generic Modules/Aeroo Reports",
"summary": "Allow Printing an Aeroo Invoice",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"depends": [
"account",
"report_aeroo",
],
"data": [
"views/res_config_settings.xml",
"views/portal.xml",
],
"assets": {
"web.assets_frontend": [
"report_aeroo_invoice/static/src/js/portal.js",
],
},
"demo": [
"demo/invoice.xml",
],
"license": "LGPL-3",
"installable": True,
}
4 changes: 4 additions & 0 deletions report_aeroo_invoice/controllers/__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 portal
40 changes: 40 additions & 0 deletions report_aeroo_invoice/controllers/portal.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/gpl).

from odoo import http
from odoo.addons.account.controllers.portal import PortalAccount
from odoo.exceptions import AccessError, MissingError
from odoo.http import request

AEROO_INVOICE_REPORT_REF = "report_aeroo_invoice.aeroo_invoice_report"


class PortalAccountWithAerooInvoiceReport(PortalAccount):

@http.route(
["/my/invoices/<int:invoice_id>"], type="http", auth="public", website=True
)
def portal_my_invoice_detail(
self, invoice_id, access_token=None, report_type=None, download=False, **kw
):
template = request.env.ref(AEROO_INVOICE_REPORT_REF, raise_if_not_found=False)

if not template or report_type != "pdf":
return super().portal_my_invoice_detail(
invoice_id,
access_token=access_token,
report_type=report_type,
download=download,
**kw
)

try:
invoice = self._document_check_access(
"account.move", invoice_id, access_token
)
except (AccessError, MissingError):
return request.redirect("/my")

return self._show_aeroo_report(
record=invoice, template=template, download=download
)
Binary file added report_aeroo_invoice/demo/invoice.odt
Binary file not shown.
19 changes: 19 additions & 0 deletions report_aeroo_invoice/demo/invoice.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<odoo noupdate="1">

<record id="aeroo_invoice_report" model="ir.actions.report">
<field name="name">Aeroo Invoice Report</field>
<field name="type">ir.actions.report</field>
<field name="model">account.move</field>
<field name="report_name">aeroo_invoice_report</field>
<field name="report_type">aeroo</field>
<field name="aeroo_in_format">odt</field>
<field name="aeroo_out_format_id" ref="report_aeroo.aeroo_mimetype_pdf_odt" />
<field name="aeroo_template_source">file</field>
<field name="aeroo_lang_eval">o.partner_id.lang</field>
<field name="aeroo_country_eval">o.partner_id.country_id</field>
<field name="aeroo_template_path">report_aeroo_invoice/demo/invoice.odt</field>
<field name="attachment_use" eval="True" />
</record>

</odoo>
43 changes: 43 additions & 0 deletions report_aeroo_invoice/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * report_aeroo_invoice
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-08 08:05+0000\n"
"PO-Revision-Date: 2024-11-08 08:05+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_invoice
#: model:ir.actions.report,name:report_aeroo_invoice.aeroo_invoice_report
#: model:ir.model.fields,field_description:report_aeroo_invoice.field_res_config_settings__aeroo_invoice_template_id
msgid "Aeroo Invoice Report"
msgstr "Rapport de facture Aeroo"

#. module: report_aeroo_invoice
#: model_terms:ir.ui.view,arch_db:report_aeroo_invoice.res_config_settings_form_with_aeroo_invoice_template
msgid "Aeroo Invoice Template"
msgstr "Modèle de facture Aeroo"

#. module: report_aeroo_invoice
#: model:ir.model,name:report_aeroo_invoice.model_res_config_settings
msgid "Config Settings"
msgstr "Paramètres de configuration"

#. module: report_aeroo_invoice
#: model:ir.model,name:report_aeroo_invoice.model_account_move
msgid "Journal Entry"
msgstr "Pièce comptable"

#. module: report_aeroo_invoice
#: model_terms:ir.ui.view,arch_db:report_aeroo_invoice.res_config_settings_form_with_aeroo_invoice_template
msgid "Main report template used for generating customer invoices."
msgstr ""
"Modèle de rapport principal utilisé pour générer les factures clients."
5 changes: 5 additions & 0 deletions report_aeroo_invoice/models/__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/gpl).

from . import account_move
from . import res_config_settings
22 changes: 22 additions & 0 deletions report_aeroo_invoice/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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 import models


class AccountMove(models.Model):

_inherit = "account.move"

def action_invoice_print(self):
"""Print the invoice using the aeroo invoice template if it is defined.
If the aeroo invoice report is not setup, fallback to the qweb template.
"""
report = self.env.ref(
"report_aeroo_invoice.aeroo_invoice_report", raise_if_not_found=False
)
if report:
return report.report_action(self)
else:
return super().invoice_print()
62 changes: 62 additions & 0 deletions report_aeroo_invoice/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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 import api, fields, models


class ResConfigSettingsWithAerooInvoiceTemplate(models.TransientModel):

_inherit = "res.config.settings"

aeroo_invoice_template_id = fields.Many2one(
"ir.actions.report",
"Aeroo Invoice Report",
domain="[('report_type', '=', 'aeroo'), ('model', '=', 'account.move')]",
)

@api.model
def get_values(self):
res = super().get_values()
template = self.env.ref(
"report_aeroo_invoice.aeroo_invoice_report", raise_if_not_found=False
)
res["aeroo_invoice_template_id"] = template.id if template else False
return res

@api.model
def set_values(self):
super().set_values()
if self.aeroo_invoice_template_id:
self._update_aeroo_invoice_template()
else:
self._empty_aeroo_invoice_template()

def _update_aeroo_invoice_template(self):
ref = self.env["ir.model.data"].search(
[
("module", "=", "report_aeroo_invoice"),
("name", "=", "aeroo_invoice_report"),
],
limit=1,
)

if ref:
ref.res_id = self.aeroo_invoice_template_id.id
else:
self.env["ir.model.data"].create(
{
"module": "report_aeroo_invoice",
"name": "aeroo_invoice_report",
"model": "ir.actions.report",
"res_id": self.aeroo_invoice_template_id.id,
"noupdate": True,
}
)

def _empty_aeroo_invoice_template(self):
self.env["ir.model.data"].search(
[
("module", "=", "report_aeroo_invoice"),
("name", "=", "aeroo_invoice_report"),
]
).unlink()
Binary file added report_aeroo_invoice/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions report_aeroo_invoice/static/src/js/portal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
odoo.define('report_aeroo_invoice.AccountPortalSidebar', function (require) {
'use strict';

/**
Override all methods of AccountPortalSidebar.
These methods are tightly coupled with the qweb invoice report.
Without overriding these methods, an error is raised because the content of
the iframe is a pdf and not an html document.
The solution was to rewrite the whole file, because there is not much code left.
**/

require('account.AccountPortalSidebar')
var publicWidget = require('web.public.widget');
var PortalSidebar = require('portal.PortalSidebar');

publicWidget.registry.AccountPortalSidebar = PortalSidebar.extend({
selector: '.o_portal_invoice_sidebar',
});
});
4 changes: 4 additions & 0 deletions report_aeroo_invoice/tests/__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/gpl).

from . import test_res_config_settings
28 changes: 28 additions & 0 deletions report_aeroo_invoice/tests/test_res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.tests.common import TransactionCase


class TestResConfigSettingsWithAerooReport(TransactionCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.wizard = cls.env["res.config.settings"].create({})
cls.wizard.get_values()
cls.report = cls.env.ref("report_aeroo_invoice.aeroo_invoice_report")

def test_empty_aeroo_invoice_template_id(self):
self.assertEqual(self.wizard.aeroo_invoice_template_id, self.report)
self.wizard.aeroo_invoice_template_id = None
self.wizard.execute()
self.wizard = self.env["res.config.settings"].create({})
self.assertFalse(self.wizard.aeroo_invoice_template_id)

def test_change_aeroo_invoice_template_id(self):
self.assertEqual(self.wizard.aeroo_invoice_template_id, self.report)
report_copy = self.report.copy({"report_name": "new_aeroo_invoice_report"})
self.wizard.aeroo_invoice_template_id = report_copy
self.wizard.execute()
self.assertEqual(self.wizard.aeroo_invoice_template_id, report_copy)
15 changes: 15 additions & 0 deletions report_aeroo_invoice/views/portal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<template id="portal_invoice_page" name="Portal Invoice With PDF Report" inherit_id="account.portal_invoice_page">
<xpath expr="//iframe" position="replace">
<object
t-att-data="invoice.get_portal_url(report_type='pdf', anchor='toolbar=0')" type="application/pdf"
width="100%" height="100%"
style="min-height: 800px"
/>
</xpath>
<xpath expr="//div[hasclass('o_portal_html_loader')]" position="replace" />
</template>

</odoo>
26 changes: 26 additions & 0 deletions report_aeroo_invoice/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="res_config_settings_form_with_aeroo_invoice_template" model="ir.ui.view">
<field name="name">Account Config With Aeroo Invoice Template</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="account.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="invoicing_settings" position="inside">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<label string="Aeroo Invoice Template" for="aeroo_invoice_template_id" />
<div class="text-muted">
Main report template used for generating customer invoices.
</div>
<div class="content-group">
<field name="aeroo_invoice_template_id" options="{'no_create': True}" />
</div>
</div>
</div>
</div>
</field>
</record>

</odoo>

0 comments on commit 5c17236

Please sign in to comment.