From c5e1716d2ef150cb5b8854dc690e834849ee2a71 Mon Sep 17 00:00:00 2001 From: Camille Spiritus Date: Tue, 30 May 2023 06:59:52 +0000 Subject: [PATCH] [FIX] account/l10n_ch: QR Bill: adapt QR header to invoice's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Switzerland, since 16.0, the QR Bill page always has the external_layout template, whatever template the user chose for his invoices.  This was a "lesser evil" choice to allow the user to print QR-bills : BootStrap5 and wkhtmltopdf were not compatible, causing a display bug and generating incorrect QR Bills before this.   See for an example the task-3037921. Returned to the original behaviour, namely : - Display the invoice header on the QR Bill ; - Adapt said header display to the layout chosen by the user ; - Fixed Din5008 display.  task-3241502 closes odoo/odoo#132051 X-original-commit: 061a6780d445b9e23e62ef69b9da2503cb212cfb Signed-off-by: Laurent Smet (las) Signed-off-by: Camille Spiritus (casp) --- addons/l10n_ch/models/ir_actions_report.py | 40 +++++++++++- addons/l10n_ch/report/swissqr_report.xml | 61 +++++++++++-------- .../static/src/scss/report_swissqr.scss | 6 +- addons/l10n_din5008/report/din5008_report.xml | 22 ++++--- 4 files changed, 88 insertions(+), 41 deletions(-) diff --git a/addons/l10n_ch/models/ir_actions_report.py b/addons/l10n_ch/models/ir_actions_report.py index fa99cfe483c..3d9f35eca3e 100644 --- a/addons/l10n_ch/models/ir_actions_report.py +++ b/addons/l10n_ch/models/ir_actions_report.py @@ -43,9 +43,43 @@ class IrActionsReport(models.Model): # Render the additional reports. streams_to_append = {} if qr_inv_ids: - qr_res = self._render_qweb_pdf_prepare_streams('l10n_ch.l10n_ch_qr_report', data, res_ids=qr_inv_ids) - for invoice_id, stream in qr_res.items(): - streams_to_append[invoice_id] = stream + qr_res = self._render_qweb_pdf_prepare_streams( + 'l10n_ch.l10n_ch_qr_report', + { + **data, + 'skip_headers': False, + }, + res_ids=qr_inv_ids, + ) + header = self.env.ref('l10n_ch.l10n_ch_qr_header', raise_if_not_found=False) + if header: + # Make a separated rendering to get the a page containing the company header. Then, merge the qr bill with it. + + header_res = self._render_qweb_pdf_prepare_streams( + 'l10n_ch.l10n_ch_qr_header', + { + **data, + 'skip_headers': True, + }, + res_ids=qr_inv_ids, + ) + + for invoice_id, stream in qr_res.items(): + qr_pdf = OdooPdfFileReader(stream['stream'], strict=False) + header_pdf = OdooPdfFileReader(header_res[invoice_id]['stream'], strict=False) + + page = header_pdf.getPage(0) + page.mergePage(qr_pdf.getPage(0)) + + output_pdf = OdooPdfFileWriter() + output_pdf.addPage(page) + new_pdf_stream = io.BytesIO() + output_pdf.write(new_pdf_stream) + streams_to_append[invoice_id] = {'stream': new_pdf_stream} + else: + for invoice_id, stream in qr_res.items(): + streams_to_append[invoice_id] = stream + # Add to results for invoice_id, additional_stream in streams_to_append.items(): invoice_stream = res[invoice_id]['stream'] diff --git a/addons/l10n_ch/report/swissqr_report.xml b/addons/l10n_ch/report/swissqr_report.xml index ff51c6832c2..d378d7a9d81 100644 --- a/addons/l10n_ch/report/swissqr_report.xml +++ b/addons/l10n_ch/report/swissqr_report.xml @@ -24,22 +24,30 @@ -