[FIX] account/l10n_ch: QR Bill: adapt QR header to invoice's

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) <las@odoo.com>
Signed-off-by: Camille Spiritus (casp) <casp@odoo.com>
This commit is contained in:
Camille Spiritus
2023-08-16 19:04:40 +02:00
committed by casp-odoo
parent f20caf3add
commit c5e1716d2e
4 changed files with 88 additions and 41 deletions
+37 -3
View File
@@ -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']
+35 -26
View File
@@ -24,22 +24,30 @@
<field name="paperformat_id" ref="l10n_ch.paperformat_euro_no_margin"/>
</record>
<template id="l10n_ch_swissqr_template">
<t t-set="o" t-value="o.with_context(lang=lang)"/>
<t t-set="company" t-value="o.company_id"/>
<t t-call="web.external_layout_standard">
<!-- add default margin for header (matching A4 European margin) -->
<t t-set="report_header_style">padding-top:6.2mm; padding-left:8.2mm; padding-right:8.2mm;</t>
<record id="l10n_ch_qr_header" model="ir.actions.report">
<field name="name">QR-bill Header</field>
<field name="model">account.move</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">l10n_ch.qr_report_header</field>
<field name="report_file">l10n_ch.qr_report_header</field>
</record>
<template id="l10n_ch_header_template">
<t t-call="web.external_layout">
<!--The following elements are necessary for the header to be displayed correctly.-->
<br/>
<p>&amp;nbsp;</p>
</t>
</template>
<template id="l10n_ch_swissqr_template">
<div class="article">
<t t-set="o" t-value="o.with_context(lang=lang)"/>
<t t-set="company" t-value="o.company_id"/>
<t t-set="formated_amount" t-value="'{:,.2f}'.format(o.amount_residual).replace(',','\xa0')"/>
<t t-set="is_qrr" t-value="o.partner_bank_id.l10n_ch_qr_iban"/>
<t t-set="is_scor" t-value="o.partner_bank_id._is_iso11649_reference(o.payment_reference)"/>
<div class="swissqr_page_title">
<h1>QR-bill for invoice <t t-out="o.name"/></h1>
</div>
<div class="swissqr_content_v2">
<div class="swissqr_receipt">
@@ -61,9 +69,7 @@
<br/>
<span t-out="o.partner_bank_id.acc_holder_name or o.company_id.name"/><br/>
<span t-field="o.company_id.street"/><br/>
<t t-if="o.company_id.country_id.code != 'CH'">
<span t-field="o.company_id.country_id.code"/>
</t>
<span t-field="o.company_id.country_id.code"/>
<span t-field="o.company_id.zip"/>
<span t-field="o.company_id.city"/><br/>
<br/>
@@ -94,9 +100,7 @@
<span t-field="o.partner_id.commercial_partner_id.name"/><br/>
<span t-field="o.partner_id.street"/>
<span t-field="o.partner_id.street2"/><br/>
<t t-if="o.partner_id.country_id.code != 'CH'">
<span t-field="o.partner_id.country_id.code"/>
</t>
<span t-field="o.partner_id.country_id.code"/>
<span t-field="o.partner_id.zip"/>
<span t-field="o.partner_id.city"/>
</div>
@@ -177,9 +181,7 @@
<br/>
<span t-out="o.partner_bank_id.acc_holder_name or o.company_id.name"/><br/>
<span t-field="o.company_id.street"/><br/>
<t t-if="o.company_id.country_id.code != 'CH'">
<span t-field="o.company_id.country_id.code"/>
</t>
<span t-field="o.company_id.country_id.code"/>
<span t-field="o.company_id.zip"/>
<span t-field="o.company_id.city"/><br/>
<br/>
@@ -221,19 +223,15 @@
<span t-field="o.partner_id.commercial_partner_id.name"/><br/>
<span t-field="o.partner_id.street"> </span>
<span t-field="o.partner_id.street2"/><br/>
<t t-if="o.partner_id.country_id.code != 'CH'">
<span t-field="o.partner_id.country_id.code"/>
</t>
<span t-field="o.partner_id.country_id.code"/>
<span t-field="o.partner_id.zip"/>
<span t-field="o.partner_id.city"/><br/>
<br/>
</div>
</div>
</div>
</div>
</t>
</div>
</template>
<template id="l10n_ch.qr_report_main">
@@ -244,6 +242,17 @@
</t>
</t>
</template>
<template id="l10n_ch.qr_report_header">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="invoice">
<t t-set="o" t-value="invoice"/>
<t t-set="lang" t-value="o.partner_id.lang"/>
<t t-call="l10n_ch.l10n_ch_header_template" t-lang="lang"/>
</t>
</t>
</template>
<template id="minimal_layout_with_report_attribute" inherit_id="web.minimal_layout">
<body position="attributes">
<attribute name="t-att-data-report-id">report_xml_id</attribute>
@@ -19,7 +19,7 @@ body.l10n_ch_qr{
/* Disable custom bakground */
.o_report_layout_striped {
background: none;
background-color: white;
min-height: 0;
}
}
@@ -53,7 +53,7 @@ body.l10n_ch_qr{
}
/* New QR Bill code */
background-color: white;
background-color: white !important;
/* Disable custom font-family */
.o_company_2_layout {
@@ -77,6 +77,7 @@ body.l10n_ch_qr{
}
.swissqr_receipt {
background-color: white !important;
position: absolute;
left: 0mm;
top: 192mm * $l10n-ch-qr-ratio;
@@ -121,6 +122,7 @@ body.l10n_ch_qr{
}
.swissqr_body {
background-color: white !important;
position: absolute;
top: 192mm * $l10n-ch-qr-ratio;
left: 62mm * $l10n-ch-qr-ratio;
+12 -10
View File
@@ -91,16 +91,18 @@
</div>
</td>
</tr>
<tr t-if="o and 'l10n_din5008_addresses' in o">
<t t-foreach="o.l10n_din5008_addresses" t-as="doc_address">
<td>
<div class="shipping_address">
<strong><t t-out="doc_address[0]"/></strong>
<div t-out="doc_address[1]" t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}'/>
</div>
</td>
</t>
</tr>
<div t-if="not skip_headers">
<tr t-if="o and 'l10n_din5008_addresses' in o">
<t t-foreach="o.l10n_din5008_addresses" t-as="doc_address">
<td>
<div class="shipping_address">
<strong><t t-esc="doc_address[0]"/></strong>
<div t-esc="doc_address[1]" t-options='{"widget": "contact", "fields": ["address", "name", "phone"], "no_marker": True}'/>
</div>
</td>
</t>
</tr>
</div>
</table>
<h2>
<span t-if="not o and not docs"><t t-out="company.l10n_din5008_document_title"/></span>