From d3a9fac90b75ba98accb03bd522206d76341a800 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 12 Apr 2017 14:22:04 +0200 Subject: [PATCH] Add option py3o_multi_in_one for Py3o reports --- report_py3o/models/ir_actions_report_xml.py | 6 ++++++ report_py3o/models/py3o_report.py | 18 +++++++++++++----- report_py3o/views/ir_report.xml | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/report_py3o/models/ir_actions_report_xml.py b/report_py3o/models/ir_actions_report_xml.py index cfbfeb41..5539155c 100644 --- a/report_py3o/models/ir_actions_report_xml.py +++ b/report_py3o/models/ir_actions_report_xml.py @@ -80,6 +80,12 @@ class IrActionsReportXml(models.Model): "or an absolute path on your server." )) report_type = fields.Selection(selection_add=[('py3o', "Py3o")]) + py3o_multi_in_one = fields.Boolean( + string='Multiple Records in a Single Report', + help="If you execute a report on several records, " + "by default Odoo will generate a ZIP file that contains as many " + "files as selected records. If you enable this option, Odoo will " + "generate instead a single report for the selected records.") @api.model def render_report(self, res_ids, name, data): diff --git a/report_py3o/models/py3o_report.py b/report_py3o/models/py3o_report.py index 79c9ffcc..6b76aa35 100644 --- a/report_py3o/models/py3o_report.py +++ b/report_py3o/models/py3o_report.py @@ -282,8 +282,9 @@ class Py3oReport(models.TransientModel): with open(result_path, 'w+') as fd: for chunk in r.iter_content(chunk_size): fd.write(chunk) - self._postprocess_report( - result_path, model_instance.id, save_in_attachment) + if len(model_instance) == 1: + self._postprocess_report( + result_path, model_instance.id, save_in_attachment) return result_path @api.multi @@ -345,10 +346,17 @@ class Py3oReport(models.TransientModel): save_in_attachment = self._check_attachment_use( res_ids, self.ir_actions_report_xml_id) or {} reports_path = [] - for model_instance in model_instances: + if ( + len(res_ids) > 1 and + self.ir_actions_report_xml_id.py3o_multi_in_one): reports_path.append( - self._get_or_create_single_report( - model_instance, data, save_in_attachment)) + self._create_single_report( + model_instances, data, save_in_attachment)) + else: + for model_instance in model_instances: + reports_path.append( + self._get_or_create_single_report( + model_instance, data, save_in_attachment)) result_path, filetype = self._merge_results(reports_path) reports_path.append(result_path) diff --git a/report_py3o/views/ir_report.xml b/report_py3o/views/ir_report.xml index 0b74a52f..19f51f72 100644 --- a/report_py3o/views/ir_report.xml +++ b/report_py3o/views/ir_report.xml @@ -15,6 +15,7 @@ +