Skip to content

Commit

Permalink
[FIX] l10n_ch : fix body style in swissqr_report
Browse files Browse the repository at this point in the history
To reproduce
============

- Create a company with a complete Swiss address (street, city, zip and country).
- Install the l10n_ch modules and install the Swiss plan comptable in the Settings of the Accounting app.
- Go to Accounting > Configuration > Settings > Activate the "QR codes" > Save
- Go to Accounting > Configuration > Journals > Choose the journal for the invoices > In "Advanced settings" verify that the communication type is "Based on invoice" and the communication standard is "Switzerland"
- Go to Accounting > Configuration > Journals > Select your bank journal(s) > Verify that you have set up your bank account number and the name of the bank
- Go to the Contact app > Configuration > Bank Accounts > Choose the one you use for the QR-bills > Edit > In "ISR Client Identification Number" refer a client number and make sure account type is 'IBAN' > Save.
- Verify that you have a complete address on the contact form of the customer (street, city, zip and country).
- create multiple invoices for this client
- try to print QR-bill for these invoices at once -> and assert error is raised

Purpose
=======

the `assert len(outlines_pages) == len(res_ids)` fails because the generated pdf
contains only a single invoice.

this issue is caused by the line `<script>document.body.className += " l10n_ch_qr";</script>` in `swissqr_report.xml`,
when `wkhtmltopdf` generates the pdf from html, it doesn't wait for all javascript to finish before rendering the page,
which lead to not execute the script `<script>document.body.className += " l10n_ch_qr";</script>` for some pages then the final pdf
is missing some pages.

Specification
=============

To solve the issue we removed the javascript block `<script>document.body.className += " l10n_ch_qr";</script>` from the template
and move it to python, by setting the body style when generating the html.

opw-2772396

closes odoo#89431

X-original-commit: 318eb55
Signed-off-by: abla001 <abla@odoo.com>
  • Loading branch information
abla001 committed Apr 22, 2022
1 parent cc09ab2 commit 1df1470
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions addons/l10n_ch/report/swissqr_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
<template id="l10n_ch_swissqr_template">
<t t-set="o" t-value="o.with_context(lang=lang)"/>
<t t-call="web.external_layout">

<!-- add class to body tag -->
<script>document.body.className += " l10n_ch_qr";</script>
<!-- TODO master: remove this -->
<script t-if="0">document.body.className += " l10n_ch_qr";</script>
<!-- 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>

Expand Down Expand Up @@ -208,5 +207,10 @@
</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>
</body>
</template>
</data>
</odoo>
3 changes: 1 addition & 2 deletions addons/l10n_ch/static/src/scss/report_swissqr.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
src: url('../font/LiberationSans-Regular.woff') format('woff');
}


body.l10n_ch_qr {
body.l10n_ch_qr, body[data-oe-report="l10n_ch.l10n_ch_qr_report"] {
padding: 0;

/* Disable custom bakground */
Expand Down
2 changes: 1 addition & 1 deletion addons/web/views/report_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
}
</script>
</head>
<body class="container" t-att-onload="subst and 'subst()'" style="overflow:hidden">
<body class="container" t-att-data-report-id="report_xml_id" t-att-onload="subst and 'subst()'" style="overflow:hidden">
<t t-out="body"/>
</body>
</html>
Expand Down
3 changes: 2 additions & 1 deletion odoo/addons/base/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ def _prepare_html(self, html):
body = layout_with_lang._render({
'subst': False,
'body': Markup(lxml.html.tostring(node, encoding='unicode')),
'base_url': base_url
'base_url': base_url,
'report_xml_id' : self.xml_id
})
bodies.append(body)
if node.get('data-oe-model') == self.model:
Expand Down

0 comments on commit 1df1470

Please sign in to comment.