[FIX] base: Fix PDF generation

Suppose we are printing a PDF on multiple records but having some of them excluded during the _prepare_html.
So, suppose these records are [20, 21].
If [21] is excluded during the rendering because nothing to render, the resulting html will contains only [20].
That is leading to a traceback when checking the outlines because of

assert len(outlines_pages) == len(res_ids)

This commit avoids to check the outlines if we don't care about generating attachments.
Then, we don't need to split the PDF in that case.

closes odoo/odoo#94204

X-original-commit: 210e63ab8b036bd20c68b1e03462c75af12aa326
Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
Signed-off-by: Laurent Smet <las@odoo.com>
This commit is contained in:
Laurent Smet
2022-06-22 12:15:03 +02:00
parent 9773469bb3
commit 38e4a5fbc3
+4 -7
View File
@@ -717,15 +717,12 @@ class IrActionsReport(models.Model):
# Split the pdf for each record using the PDF outlines.
html_ids_wo_none = [x for x in html_ids if x]
if len(res_ids_wo_stream) == 1:
if not self.attachment:
# Splitting the pdf is not needed since we don't have any attachment to generate.
collected_streams[False] = {'stream': pdf_content_stream}
elif len(res_ids_wo_stream) == 1:
# Only one record: append the whole PDF.
collected_streams[res_ids_wo_stream[0]]['stream'] = pdf_content_stream
elif not html_ids_wo_none:
# When rendering some html without a one to one match between each res_id and a document
# 'html_ids' contains some 'None' values. In that case, there is nothing to split and the content
# can be returned directly.
collected_streams[False] = {'stream': pdf_content_stream}
else:
# 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.