[FIX] l10n_ch: fix qr-bills printing in batch
Since the fix of the QR bill headers (see task-3241502, PR:https://github.com/odoo/odoo/pull/130478), the print in batch functionality raises a stack trace. This is because the render_qweb_pdf_prepare_streams method in base/ir_actions_report.py wasn't meant to handle multiple pages report without specific titles in its HTML structure, which is here the case since the QR bill fixing merges the top of one page with the end of another, therefore creating a peculiar structure. In those cases we can consider that if each non-generated stream corresponds exactly to one page in the PDF reader, this is a simple batch printing case and we can just handle each page separately. task-3241502 closes odoo/odoo#132816 X-original-commit: 84fdd2eb11e42f0422dd62961aea7fe4e6f52da3 Signed-off-by: Laurent Smet (las) <las@odoo.com> Signed-off-by: Camille Spiritus (casp) <casp@odoo.com>
This commit is contained in:
@@ -768,13 +768,25 @@ class IrActionsReport(models.Model):
|
||||
return collected_streams
|
||||
|
||||
# In case of multiple docs, we need to split the pdf according the records.
|
||||
# To do so, we split the pdf based on top outlines computed by wkhtmltopdf.
|
||||
# In the simplest case of 1 res_id == 1 page, we use the PDFReader to print the
|
||||
# pages one by one.
|
||||
html_ids_wo_none = [x for x in html_ids if x]
|
||||
reader = PdfFileReader(pdf_content_stream)
|
||||
if reader.numPages == len(res_ids_wo_stream):
|
||||
for i in range(reader.numPages):
|
||||
attachment_writer = PdfFileWriter()
|
||||
attachment_writer.addPage(reader.getPage(i))
|
||||
stream = io.BytesIO()
|
||||
attachment_writer.write(stream)
|
||||
collected_streams[res_ids[i]]['stream'] = stream
|
||||
return collected_streams
|
||||
|
||||
# In cases where the number of res_ids != the number of pages,
|
||||
# we split the pdf based on top outlines computed by wkhtmltopdf.
|
||||
# An outline is a <h?> html tag found on the document. To retrieve this table,
|
||||
# we look on the pdf structure using pypdf to compute the outlines_pages from
|
||||
# the top level heading in /Outlines.
|
||||
html_ids_wo_none = [x for x in html_ids if x]
|
||||
if len(res_ids_wo_stream) > 1 and set(res_ids_wo_stream) == set(html_ids_wo_none):
|
||||
reader = PdfFileReader(pdf_content_stream)
|
||||
root = reader.trailer['/Root']
|
||||
has_valid_outlines = '/Outlines' in root and '/First' in root['/Outlines']
|
||||
if not has_valid_outlines:
|
||||
|
||||
Reference in New Issue
Block a user