Browse Source

Add option py3o_multi_in_one for Py3o reports

pull/258/head
Alexis de Lattre 8 years ago
committed by Laurent Mignon (ACSONE)
parent
commit
5173ca28c3
  1. 6
      report_py3o/models/ir_actions_report_xml.py
  2. 18
      report_py3o/models/py3o_report.py
  3. 1
      report_py3o/views/ir_report.xml

6
report_py3o/models/ir_actions_report_xml.py

@ -80,6 +80,12 @@ class IrActionsReportXml(models.Model):
"or an absolute path on your server." "or an absolute path on your server."
)) ))
report_type = fields.Selection(selection_add=[('py3o', "Py3o")]) 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 @api.model
def render_report(self, res_ids, name, data): def render_report(self, res_ids, name, data):

18
report_py3o/models/py3o_report.py

@ -282,8 +282,9 @@ class Py3oReport(models.TransientModel):
with open(result_path, 'w+') as fd: with open(result_path, 'w+') as fd:
for chunk in r.iter_content(chunk_size): for chunk in r.iter_content(chunk_size):
fd.write(chunk) 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 return result_path
@api.multi @api.multi
@ -345,10 +346,17 @@ class Py3oReport(models.TransientModel):
save_in_attachment = self._check_attachment_use( save_in_attachment = self._check_attachment_use(
res_ids, self.ir_actions_report_xml_id) or {} res_ids, self.ir_actions_report_xml_id) or {}
reports_path = [] 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( 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) result_path, filetype = self._merge_results(reports_path)
reports_path.append(result_path) reports_path.append(result_path)

1
report_py3o/views/ir_report.xml

@ -15,6 +15,7 @@
<group name="py3o_params"> <group name="py3o_params">
<field name="py3o_filetype" /> <field name="py3o_filetype" />
<field name="py3o_multi_in_one"/>
<field name="py3o_is_local_fusion"/> <field name="py3o_is_local_fusion"/>
<field name="py3o_server_id" /> <field name="py3o_server_id" />
<field name="py3o_template_id" /> <field name="py3o_template_id" />

Loading…
Cancel
Save