[FIX] base: Fix pdf generation with 'attachment_use'

When generating a PDF report with an action having 'attachment_use' set and when the pdf of at least one record has been already generated but not all, an error is raised for no reason.

X-original-commit: 7ad19283ea5c89a6629c8433b468d1dac3fdad4d
Part-of: odoo/odoo#93516
This commit is contained in:
Laurent Smet
2022-06-14 10:36:07 +02:00
parent f7a42ecb5a
commit bf6d58f165
+3 -3
View File
@@ -688,7 +688,7 @@ class IrActionsReport(models.Model):
bodies, html_ids, header, footer, specific_paperformat_args = self._prepare_html(html, report_model=self_sudo.model)
if self_sudo.attachment and set(res_ids) != set(html_ids):
if self_sudo.attachment and set(res_ids_wo_stream) != set(html_ids):
raise UserError(_(
"The report's template %r is wrong, please contact your administrator. \n\n"
"Can not separate file to save as attachment because the report's template does not contains the"
@@ -745,7 +745,7 @@ class IrActionsReport(models.Model):
node = node['/Next']
outlines_pages = sorted(set(outlines_pages))
# There should be only one top-level heading by document
assert len(outlines_pages) == len(res_ids_wo_stream)
assert len(outlines_pages) == len(res_ids)
# There should be a top-level heading on first page
assert outlines_pages[0] == 0
for i, num in enumerate(outlines_pages):
@@ -755,7 +755,7 @@ class IrActionsReport(models.Model):
attachment_writer.addPage(reader.getPage(j))
stream = io.BytesIO()
attachment_writer.write(stream)
collected_streams[res_ids_wo_stream[i]]['stream'] = stream
collected_streams[res_ids[i]]['stream'] = stream
return collected_streams