From 070d7e5e9170fdad32be726814d2bc1b0936ea9f Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Thu, 9 Jun 2022 13:46:34 +0000 Subject: [PATCH] [FIX] base: Fix PDF generation with not exactly one html doc per record When the html is grouping some records together, there is no exactly one document per record. In that case, the wkhtmltopdf outlines must not be checked. closes odoo/odoo#93516 X-original-commit: c1faefce79bae6ff6014e7af7f675e98f5091a07 Signed-off-by: Olivier Colson (oco) Signed-off-by: Laurent Smet --- odoo/addons/base/models/ir_actions_report.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_actions_report.py b/odoo/addons/base/models/ir_actions_report.py index aafbe9ae402..e2d194303b3 100644 --- a/odoo/addons/base/models/ir_actions_report.py +++ b/odoo/addons/base/models/ir_actions_report.py @@ -717,9 +717,15 @@ 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: # 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. @@ -808,7 +814,7 @@ class IrActionsReport(models.Model): _logger.info("The PDF documents %r are now saved in the database", attachment_names) # Merge all streams together for a single record. - streams_to_merge = [x['stream'] for x in collected_streams.values()] + streams_to_merge = [x['stream'] for x in collected_streams.values() if x['stream']] if len(streams_to_merge) == 1: pdf_content = streams_to_merge[0].getvalue() else: