@@ -320,16 +320,14 @@ def _get_or_create_single_report(
320
320
321
321
def _zip_results (self , reports_path ):
322
322
self .ensure_one ()
323
- zfname_prefix = self .ir_actions_report_id .name
324
323
fd , result_path = tempfile .mkstemp (suffix = "zip" , prefix = "py3o-zip-result" )
325
324
os .close (fd )
326
325
with ZipFile (result_path , "w" , ZIP_DEFLATED ) as zf :
327
- cpt = 0
328
- for report in reports_path :
329
- fname = "%s_%d.%s" % (zfname_prefix , cpt , report .split ("." )[- 1 ])
326
+ for report_instance , report in reports_path .items ():
327
+ fname = self .ir_actions_report_id .gen_report_download_filename (
328
+ report_instance .ids , {}
329
+ )
330
330
zf .write (report , fname )
331
-
332
- cpt += 1
333
331
return result_path
334
332
335
333
@api .model
@@ -353,12 +351,13 @@ def _merge_pdf(self, reports_path):
353
351
def _merge_results (self , reports_path ):
354
352
self .ensure_one ()
355
353
filetype = self .ir_actions_report_id .py3o_filetype
354
+ path_list = list (reports_path .values ())
356
355
if not reports_path :
357
356
return False , False
358
357
if len (reports_path ) == 1 :
359
- return reports_path [0 ], filetype
358
+ return path_list [0 ], filetype
360
359
if filetype == formats .FORMAT_PDF :
361
- return self ._merge_pdf (reports_path ), formats .FORMAT_PDF
360
+ return self ._merge_pdf (path_list ), formats .FORMAT_PDF
362
361
else :
363
362
return self ._zip_results (reports_path ), "zip"
364
363
@@ -374,22 +373,23 @@ def _cleanup_tempfiles(self, temporary_files):
374
373
def create_report (self , res_ids , data ):
375
374
"""Override this function to handle our py3o report"""
376
375
model_instances = self .env [self .ir_actions_report_id .model ].browse (res_ids )
377
- reports_path = []
376
+ reports_path = {}
378
377
if len (res_ids ) > 1 and self .ir_actions_report_id .py3o_multi_in_one :
379
- reports_path .append (self ._create_single_report (model_instances , data ))
378
+ reports_path [model_instances ] = self ._create_single_report (
379
+ model_instances , data
380
+ )
380
381
else :
381
382
existing_reports_attachment = self .ir_actions_report_id ._get_attachments (
382
383
res_ids
383
384
)
384
385
for model_instance in model_instances :
385
- reports_path .append (
386
- self ._get_or_create_single_report (
387
- model_instance , data , existing_reports_attachment
388
- )
386
+ reports_path [model_instance ] = self ._get_or_create_single_report (
387
+ model_instance , data , existing_reports_attachment
389
388
)
390
389
391
390
result_path , filetype = self ._merge_results (reports_path )
392
- reports_path .append (result_path )
391
+ cleanup_path = list (reports_path .values ())
392
+ cleanup_path .append (result_path )
393
393
394
394
# Here is a little joke about Odoo
395
395
# we do all the generation process using files to avoid memory
@@ -398,5 +398,5 @@ def create_report(self, res_ids, data):
398
398
399
399
with open (result_path , "r+b" ) as fd :
400
400
res = fd .read ()
401
- self ._cleanup_tempfiles (set (reports_path ))
401
+ self ._cleanup_tempfiles (set (cleanup_path ))
402
402
return res , filetype
0 commit comments