From c4d2c2cf13b5eed8e9726577a6a67384ec3067d2 Mon Sep 17 00:00:00 2001 From: sbbaro Date: Wed, 23 Jan 2019 14:20:33 +0100 Subject: [PATCH] [FIX] base ir.actions.report order pdfs when attachment_use option selected A couple of small changes: - only run the search if streams is not empty - change streams for stream_list in the if for the final merging --- odoo/addons/base/models/ir_actions_report.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/odoo/addons/base/models/ir_actions_report.py b/odoo/addons/base/models/ir_actions_report.py index 98ea6c176a2..e5af01b2547 100644 --- a/odoo/addons/base/models/ir_actions_report.py +++ b/odoo/addons/base/models/ir_actions_report.py @@ -588,10 +588,16 @@ class IrActionsReport(models.Model): content = base64.decodestring(attachment_id.datas) streams[res_id] = io.BytesIO(content) + # A list is made with the unmapped streams and, if streams is not empty, its + # content, sorted by the table _order of the mapped records + if streams: + stream_list = unmapped_streams + [streams[rec_id.id] for rec_id in self.env[self.model].search([('id', 'in', list(streams.keys()))])] + else: + stream_list = unmapped_streams + # Build the final pdf. # If only one stream left, no need to merge them (and then, preserve embedded files). - stream_list = unmapped_streams + [streams[rec_id.id] for rec_id in self.env[self.model].search([('id', 'in', list(streams.keys()))])] - if len(streams) == 1: + if len(stream_list) == 1: result = stream_list[0].getvalue() else: writer = PdfFileWriter()