Skip to content

Commit 9b5e7eb

Browse files
committed
Merge PR #924 into 16.0
Signed-off-by HviorForgeFlow
2 parents 7470393 + 6283f0d commit 9b5e7eb

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

report_py3o/models/py3o_report.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,14 @@ def _get_or_create_single_report(
320320

321321
def _zip_results(self, reports_path):
322322
self.ensure_one()
323-
zfname_prefix = self.ir_actions_report_id.name
324323
fd, result_path = tempfile.mkstemp(suffix="zip", prefix="py3o-zip-result")
325324
os.close(fd)
326325
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+
)
330330
zf.write(report, fname)
331-
332-
cpt += 1
333331
return result_path
334332

335333
@api.model
@@ -353,12 +351,13 @@ def _merge_pdf(self, reports_path):
353351
def _merge_results(self, reports_path):
354352
self.ensure_one()
355353
filetype = self.ir_actions_report_id.py3o_filetype
354+
path_list = list(reports_path.values())
356355
if not reports_path:
357356
return False, False
358357
if len(reports_path) == 1:
359-
return reports_path[0], filetype
358+
return path_list[0], filetype
360359
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
362361
else:
363362
return self._zip_results(reports_path), "zip"
364363

@@ -374,22 +373,23 @@ def _cleanup_tempfiles(self, temporary_files):
374373
def create_report(self, res_ids, data):
375374
"""Override this function to handle our py3o report"""
376375
model_instances = self.env[self.ir_actions_report_id.model].browse(res_ids)
377-
reports_path = []
376+
reports_path = {}
378377
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+
)
380381
else:
381382
existing_reports_attachment = self.ir_actions_report_id._get_attachments(
382383
res_ids
383384
)
384385
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
389388
)
390389

391390
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)
393393

394394
# Here is a little joke about Odoo
395395
# we do all the generation process using files to avoid memory
@@ -398,5 +398,5 @@ def create_report(self, res_ids, data):
398398

399399
with open(result_path, "r+b") as fd:
400400
res = fd.read()
401-
self._cleanup_tempfiles(set(reports_path))
401+
self._cleanup_tempfiles(set(cleanup_path))
402402
return res, filetype

0 commit comments

Comments
 (0)