Skip to content
Snippets Groups Projects
Commit 951ba40c4a90 authored by damien.habets's avatar damien.habets
Browse files

Allow 1 report on multiple records

parent 8181a1c85596
No related branches found
Tags 11.0.2.4.0
1 merge request!10Allow 1 report on multiple records
......@@ -2,6 +2,11 @@
NEWS
====
11.0.2.4.0
==========
* Allow 1 report on multiple records.
11.0.2.3
========
......
......@@ -21,7 +21,7 @@
"name": "Redner",
"summary": """
Allows to generate transactional emails and documents in PDF or HTML format""",
"version": "11.0.2.0.0",
"version": "11.0.2.4.0",
"author": "XCG Consulting",
"category": "Technical",
"description": """
......
......@@ -131,18 +131,6 @@
return metadata_values
def get_report_data(self, res_id):
if not res_id:
return {}
conv = self.substitution_ids.filtered(
lambda r: r.depth == 0
).build_converter()
instance = self.env[self.model].browse(res_id)
return conv.odoo_to_message(instance)
@api.model
def get_from_report_name(self, report_name, report_type):
return self.search(
......
......@@ -46,10 +46,10 @@
)
return result_path
def _create_single_report(self, model_instance, data):
def _create_single_report(self, model_instances, data):
"""This function to generate our redner report"""
self.ensure_one()
report_xml = self.ir_actions_report_id
report_file, path = tempfile.mkstemp("." + report_xml.redner_filetype)
......@@ -50,10 +50,10 @@
"""This function to generate our redner report"""
self.ensure_one()
report_xml = self.ir_actions_report_id
report_file, path = tempfile.mkstemp("." + report_xml.redner_filetype)
data = report_xml.get_report_data(model_instance.id)
data = self._get_report_data(model_instances)
metadata = report_xml.get_report_metadata()
fformat = Formats().get_format(
......@@ -81,7 +81,7 @@
with open(report_file, "wb") as f:
f.write(content)
return self._postprocess_report(model_instance, path)
return self._postprocess_report(model_instances, path)
def _get_or_create_single_report(
self, model_instance, data, existing_reports_attachment
......@@ -189,3 +189,23 @@
res = fd.read()
self._cleanup_tempfiles(set(reports_path))
return res, filetype
def _get_report_data(self, records):
if not records:
return {}
floor_conv = self.ir_actions_report_id.substitution_ids.filtered(
lambda sub: sub.depth == 0
).build_converter()
ret = floor_conv.odoo_to_message(records) or {}
filtered_lines = self.ir_actions_report_id.substitution_ids.filtered(
lambda sub: (sub.depth == 1 and sub.keyword.startswith("records."))
)
if filtered_lines:
down_conv = filtered_lines.build_converter()
ret["records"] = [
down_conv.odoo_to_message(record) for record in records
]
return ret
......@@ -22,6 +22,7 @@
<group name="redner_params">
<field name="redner_filetype" attrs="{'required': [('report_type', '=', 'redner')]}"/>
<field name="redner_tmpl_id" attrs="{'required': [('report_type', '=', 'redner')]}" />
<field name="redner_multi_in_one" attrs="{'invisible': [('report_type', '!=', 'redner')]}" />
</group>
<button name="action_get_substitutions"
string="Get Substitutions from Rednerd Report"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment