From e997bf14b344accba9e0ca14d70b878d9e95aa61 Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Tue, 28 Apr 2020 15:07:04 +0000 Subject: [PATCH] [FIX] l10n_ch: fix QR-bill pdf report so that it matches the spec Using it as a parf of the regular invoice pdf report was wrong, as this report is subject to the margins defined in its paper format; causing issues as for the rendering of the QR report, which must be displayed at a precise location (just like ISR). wkhtmltopdf doesn't allow having different margin values in the same file, so we did just as for ISR, and now generate QR-bill in a distinct pdf. [IMP] l10n_ch: add receipt part to QR-bill pdf report closes odoo/odoo#50765 X-original-commit: 99b5306545b945810e8259f2cc447b933d316778 Signed-off-by: Laurent Smet Signed-off-by: oco-odoo --- addons/l10n_ch/i18n/l10n_ch.pot | 64 ++++++++++ addons/l10n_ch/models/account_invoice.py | 21 ++-- addons/l10n_ch/models/mail_template.py | 33 +++-- addons/l10n_ch/report/swissqr_report.xml | 113 +++++++++++++---- .../static/src/scss/report_swissqr.css | 89 -------------- .../static/src/scss/report_swissqr.scss | 116 ++++++++++++++++++ addons/l10n_ch/views/account_invoice_view.xml | 19 +++ 7 files changed, 323 insertions(+), 132 deletions(-) delete mode 100644 addons/l10n_ch/static/src/scss/report_swissqr.css create mode 100644 addons/l10n_ch/static/src/scss/report_swissqr.scss diff --git a/addons/l10n_ch/i18n/l10n_ch.pot b/addons/l10n_ch/i18n/l10n_ch.pot index 4450d5c665d..6ae9356b26e 100644 --- a/addons/l10n_ch/i18n/l10n_ch.pot +++ b/addons/l10n_ch/i18n/l10n_ch.pot @@ -575,3 +575,67 @@ msgid "" "\n" " - fill the 'bank account' field of the invoice with the postal to be used to receive the related payment. A default account will be automatically set for all invoices created after you defined a postal account for your company." msgstr "" + +#. module: l10n_ch +#: model:ir.model.fields,help:l10n_ch.field_mail_template__attachment_ids +msgid "You may attach files to this template, to be added to all emails created from this template" +msgstr "" + +#. module: l10n_ch +#: model:ir.model.fields,field_description:l10n_ch.field_res_bank__zip +#: model:ir.model.fields,field_description:l10n_ch.field_res_company__zip +msgid "Zip" +msgstr "" + +#. module: l10n_ch +#: model:ir.model.fields,help:l10n_ch.field_account_invoice__amount_by_group +msgid "type: [(name, amount, base, formated amount, formated base)]" +msgstr "" + +#: code:addons/l10n_ch/models/account_invoice.py:179 +#, python-format +msgid "Cannot generate the QR-bill. Please check you have configured the address of your company and debtor. If you are using a QR-IBAN, also check the invoice's payment reference is a QR reference." +msgstr "" + +#. module: l10n_ch +#: model_terms:ir.ui.view,arch_db:l10n_ch.l10n_ch_swissqr_template +msgid "QR-bill for invoice" +msgstr "" + +#. module: l10n_ch +#: model_terms:ir.ui.view,arch_db:l10n_ch.l10n_ch_swissqr_template +msgid "QR-bill Payment Receipt Part
\n" +"\n" +" Payable to
" +msgstr "" + +#. module: l10n_ch +#: model_terms:ir.ui.view,arch_db:l10n_ch.l10n_ch_swissqr_template +msgid "Payable to
" +msgstr "" + +#. module: l10n_ch +#: model_terms:ir.ui.view,arch_db:l10n_ch.l10n_ch_swissqr_template +msgid "
\n" +"\n" +" Reference
" +msgstr "" + +#. module: l10n_ch +#: model_terms:ir.ui.view,arch_db:l10n_ch.l10n_ch_swissqr_template +msgid "Payable by
" +msgstr "" + +#. module: l10n_ch +#: model_terms:ir.ui.view,arch_db:l10n_ch.l10n_ch_swissqr_template +msgid "Payable by
" +msgstr "" + +#. module: l10n_ch +#: model_terms:ir.ui.view,arch_db:l10n_ch.l10n_ch_swissqr_template +msgid "Acceptance point" +msgstr "" + +#. module: l10n_ch +#: model_terms:ir.ui.view,arch_db:l10n_ch.l10n_ch_swissqr_template +msgid "QR-bill Payment Part
" diff --git a/addons/l10n_ch/models/account_invoice.py b/addons/l10n_ch/models/account_invoice.py index 5e0072c76f2..c19afba614a 100644 --- a/addons/l10n_ch/models/account_invoice.py +++ b/addons/l10n_ch/models/account_invoice.py @@ -4,7 +4,7 @@ import re from odoo import models, fields, api, _ -from odoo.exceptions import ValidationError +from odoo.exceptions import ValidationError, UserError from odoo.tools.float_utils import float_split_str from odoo.tools.misc import mod10r @@ -165,14 +165,6 @@ class AccountMove(models.Model): """ return float_split_str(self.amount_residual, 2) - def display_swiss_qr_code(self): - """ Returns whether or not to print the QR-bills additional page when - generation an invoice pdf. - """ - self.ensure_one() - return self.display_qr_code and \ - self.partner_bank_id._eligible_for_qr_code('ch_qr', self.partner_id, self.currency_id) - def isr_print(self): """ Triggered by the 'Print ISR' button. """ @@ -188,6 +180,17 @@ class AccountMove(models.Model): - associate this bank with a postal reference for the currency used in this invoice\n - fill the 'bank account' field of the invoice with the postal to be used to receive the related payment. A default account will be automatically set for all invoices created after you defined a postal account for your company.""")) + def print_ch_qr_bill(self): + """ Triggered by the 'Print QR-bill' button. + """ + self.ensure_one() + + if not self.partner_bank_id._eligible_for_qr_code('ch_qr', self.partner_id, self.currency_id): + raise UserError(_("Cannot generate the QR-bill. Please check you have configured the address of your company and debtor. If you are using a QR-IBAN, also check the invoice's payment reference is a QR reference.")) + + self.l10n_ch_isr_sent = True + return self.env.ref('l10n_ch.l10n_ch_qr_report').report_action(self) + def action_invoice_sent(self): # OVERRIDE rslt = super(AccountMove, self).action_invoice_sent() diff --git a/addons/l10n_ch/models/mail_template.py b/addons/l10n_ch/models/mail_template.py index b532acc9b23..2231b42a2e6 100644 --- a/addons/l10n_ch/models/mail_template.py +++ b/addons/l10n_ch/models/mail_template.py @@ -25,18 +25,31 @@ class MailTemplate(models.Model): res_ids = [res_ids] multi_mode = False - for record in self.env[self.model].browse(res_ids): - if record.l10n_ch_isr_valid: - # We add an attachment containing the ISR - report_name = 'ISR-' + self._render_field('report_name', record.ids, compute_lang=True)[record.id] + '.pdf' + if self.model == 'account.move': + for record in self.env[self.model].browse(res_ids): + if record.l10n_ch_isr_valid: + # We add an attachment containing the ISR + inv_print_name = self._render_field('report_name', record.ids, compute_lang=True)[record.id] - pdf = self.env.ref('l10n_ch.l10n_ch_isr_report').render_qweb_pdf(record.ids)[0] - pdf = base64.b64encode(pdf) + report_name = 'ISR-' + self._render_field('report_name', record.ids, compute_lang=True)[record.id] + '.pdf' + + isr_report_name = 'ISR-' + inv_print_name + '.pdf' + qr_report_name = 'QR-bill-' + 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) + + 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 = [(isr_report_name, isr_pdf), (qr_report_name, qr_pdf)] + + record_dict = multi_mode and result[record.id] or result + attachments_list = record_dict.get('attachments', False) - record_dict = multi_mode and result[record.id] or result - attachments_list = record_dict.get('attachments', False) if attachments_list: - attachments_list.append((report_name, pdf)) + attachments_list.extend(new_attachments) else: - record_dict['attachments'] = [(report_name, pdf)] + record_dict['attachments'] = new_attachments + return result diff --git a/addons/l10n_ch/report/swissqr_report.xml b/addons/l10n_ch/report/swissqr_report.xml index 54a3450e515..6e241079fea 100644 --- a/addons/l10n_ch/report/swissqr_report.xml +++ b/addons/l10n_ch/report/swissqr_report.xml @@ -1,17 +1,75 @@ -