From c10ba87c3f783f6238c8bd194fedcb2a3b4eebec Mon Sep 17 00:00:00 2001 From: Renzo Meister Date: Tue, 19 Apr 2022 12:26:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Settings=20to=20define=20if=20ISR?= =?UTF-8?q?=20and=20QR=20should=20be=20added=20to=20email=20template,=20an?= =?UTF-8?q?d=20also=20if=20it=20should=20only=20be=20done=20when=20invoice?= =?UTF-8?q?=20is=20not=20paid=20->l10n=5Fch=5Freport=5Foptional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- l10n_ch_report_optional/__init__.py | 4 ++ l10n_ch_report_optional/__manifest__.py | 19 +++++++ l10n_ch_report_optional/models/__init__.py | 6 ++ .../models/mail_template.py | 56 +++++++++++++++++++ l10n_ch_report_optional/models/res_company.py | 19 +++++++ .../models/res_config_settings.py | 21 +++++++ .../views/res_config_settings_views.xml | 53 ++++++++++++++++++ 7 files changed, 178 insertions(+) create mode 100644 l10n_ch_report_optional/__init__.py create mode 100644 l10n_ch_report_optional/__manifest__.py create mode 100644 l10n_ch_report_optional/models/__init__.py create mode 100644 l10n_ch_report_optional/models/mail_template.py create mode 100644 l10n_ch_report_optional/models/res_company.py create mode 100644 l10n_ch_report_optional/models/res_config_settings.py create mode 100644 l10n_ch_report_optional/views/res_config_settings_views.xml diff --git a/l10n_ch_report_optional/__init__.py b/l10n_ch_report_optional/__init__.py new file mode 100644 index 0000000..013872c --- /dev/null +++ b/l10n_ch_report_optional/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/l10n_ch_report_optional/__manifest__.py b/l10n_ch_report_optional/__manifest__.py new file mode 100644 index 0000000..32ab177 --- /dev/null +++ b/l10n_ch_report_optional/__manifest__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. +# Main contributor: Nicolas Bessi. Camptocamp SA +# Financial contributors: Hasa SA, Open Net SA, +# Prisme Solutions Informatique SA, Quod SA +# Translation contributors: brain-tec AG, Agile Business Group +{ + 'name': "Switzerland - Accounting Optional Reports as Attachments", + 'description': """ + Add some parameters to define if ISR or QR Bill should be added automatically + """, + 'version': '1.0.1.0', + 'category': 'Accounting', + 'depends': ['l10n_ch'], + 'data': [ + 'views/res_config_settings_views.xml', + ], + 'license': 'LGPL-3', +} diff --git a/l10n_ch_report_optional/models/__init__.py b/l10n_ch_report_optional/models/__init__.py new file mode 100644 index 0000000..7d99f60 --- /dev/null +++ b/l10n_ch_report_optional/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. + +from . import res_config_settings +from . import mail_template +from . import res_company diff --git a/l10n_ch_report_optional/models/mail_template.py b/l10n_ch_report_optional/models/mail_template.py new file mode 100644 index 0000000..308cc91 --- /dev/null +++ b/l10n_ch_report_optional/models/mail_template.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. + +import base64 + +from flectra import api, models +from flectra.addons.l10n_ch.models.mail_template import MailTemplate + + +def generate_email(self, res_ids, fields): + """ Method overridden in order to add an attachment containing the ISR + to the draft message when opening the 'send by mail' wizard on an invoice. + This attachment generation will only occur if all the required data are + present on the invoice. Otherwise, no ISR attachment will be created, and + the mail will only contain the invoice (as defined in the mother method). + """ + result = super(MailTemplate, self).generate_email(res_ids, fields) + if self.model != 'account.move': + return result + + multi_mode = True + if isinstance(res_ids, int): + res_ids = [res_ids] + multi_mode = False + + if self.model == 'account.move': + for record in self.env[self.model].browse(res_ids): + inv_print_name = self._render_field('report_name', record.ids, compute_lang=True)[record.id] + new_attachments = [] + if not self.env.company.l10n_ignore_qr_when_reconciled or record.payment_state != 'paid': + if record.l10n_ch_isr_valid and self.env.company.l10n_add_isr_pdf: + # We add an attachment containing the ISR + isr_report_name = 'ISR-' + inv_print_name + '.pdf' + isr_pdf = self.env.ref('l10n_ch.l10n_ch_isr_report')._render_qweb_pdf(record.ids)[0] + isr_pdf = base64.b64encode(isr_pdf) + new_attachments.append((isr_report_name, isr_pdf)) + + if record.partner_bank_id._eligible_for_qr_code('ch_qr', record.partner_id, record.currency_id) and self.env.company.l10n_add_qr_pdf: + # We add an attachment containing the QR-bill + qr_report_name = 'QR-bill-' + inv_print_name + '.pdf' + qr_pdf = self.env.ref('l10n_ch.l10n_ch_qr_report')._render_qweb_pdf(record.ids)[0] + qr_pdf = base64.b64encode(qr_pdf) + new_attachments.append((qr_report_name, qr_pdf)) + + record_dict = multi_mode and result[record.id] or result + attachments_list = record_dict.get('attachments', False) + if attachments_list: + attachments_list.extend(new_attachments) + else: + record_dict['attachments'] = new_attachments + + return result + + +# Patch / Override existing Method +MailTemplate.generate_email = generate_email diff --git a/l10n_ch_report_optional/models/res_company.py b/l10n_ch_report_optional/models/res_company.py new file mode 100644 index 0000000..f7fe709 --- /dev/null +++ b/l10n_ch_report_optional/models/res_company.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. + +from flectra import fields, models + + +class Company(models.Model): + _inherit = "res.company" + + l10n_add_isr_pdf = fields.Boolean( + string='ISR-PDF', + ) + l10n_add_qr_pdf = fields.Boolean( + string='QR-PDF', + ) + l10n_ignore_qr_when_reconciled = fields.Boolean( + string='Ignore QR when reconciled', + help='Do not add QR Bill when invoice is reconciled', + ) diff --git a/l10n_ch_report_optional/models/res_config_settings.py b/l10n_ch_report_optional/models/res_config_settings.py new file mode 100644 index 0000000..cd8639d --- /dev/null +++ b/l10n_ch_report_optional/models/res_config_settings.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. + +from flectra import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + l10n_add_isr_pdf = fields.Boolean( + related='company_id.l10n_add_isr_pdf', + readonly=False, + ) + l10n_add_qr_pdf = fields.Boolean( + related='company_id.l10n_add_qr_pdf', + readonly=False, + ) + l10n_ignore_qr_when_reconciled = fields.Boolean( + related='company_id.l10n_ignore_qr_when_reconciled', + readonly=False, + ) diff --git a/l10n_ch_report_optional/views/res_config_settings_views.xml b/l10n_ch_report_optional/views/res_config_settings_views.xml new file mode 100644 index 0000000..371908f --- /dev/null +++ b/l10n_ch_report_optional/views/res_config_settings_views.xml @@ -0,0 +1,53 @@ + + + + + res.config.settings.view.form.inherit.l10n.ch + res.config.settings + + + +

Send & Print: adds additional single pdf

+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+