|
@ -77,7 +77,6 @@ class Py3oReport(models.TransientModel): |
|
|
comodel_name="ir.actions.report", required=True |
|
|
comodel_name="ir.actions.report", required=True |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _is_valid_template_path(self, path): |
|
|
def _is_valid_template_path(self, path): |
|
|
""" Check if the path is a trusted path for py3o templates. |
|
|
""" Check if the path is a trusted path for py3o templates. |
|
|
""" |
|
|
""" |
|
@ -100,7 +99,6 @@ class Py3oReport(models.TransientModel): |
|
|
) |
|
|
) |
|
|
return is_valid |
|
|
return is_valid |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _is_valid_template_filename(self, filename): |
|
|
def _is_valid_template_filename(self, filename): |
|
|
""" Check if the filename can be used as py3o template |
|
|
""" Check if the filename can be used as py3o template |
|
|
""" |
|
|
""" |
|
@ -116,7 +114,6 @@ class Py3oReport(models.TransientModel): |
|
|
logger.warning("%s is not a valid Py3o template filename", filename) |
|
|
logger.warning("%s is not a valid Py3o template filename", filename) |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _get_template_from_path(self, tmpl_name): |
|
|
def _get_template_from_path(self, tmpl_name): |
|
|
""" Return the template from the path to root of the module if specied |
|
|
""" Return the template from the path to root of the module if specied |
|
|
or an absolute path on your server |
|
|
or an absolute path on your server |
|
@ -137,7 +134,6 @@ class Py3oReport(models.TransientModel): |
|
|
return tmpl.read() |
|
|
return tmpl.read() |
|
|
return None |
|
|
return None |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _get_template_fallback(self, model_instance): |
|
|
def _get_template_fallback(self, model_instance): |
|
|
""" |
|
|
""" |
|
|
Return the template referenced in the report definition |
|
|
Return the template referenced in the report definition |
|
@ -147,7 +143,6 @@ class Py3oReport(models.TransientModel): |
|
|
report_xml = self.ir_actions_report_id |
|
|
report_xml = self.ir_actions_report_id |
|
|
return self._get_template_from_path(report_xml.py3o_template_fallback) |
|
|
return self._get_template_from_path(report_xml.py3o_template_fallback) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def get_template(self, model_instance): |
|
|
def get_template(self, model_instance): |
|
|
"""private helper to fetch the template data either from the database |
|
|
"""private helper to fetch the template data either from the database |
|
|
or from the default template file provided by the implementer. |
|
|
or from the default template file provided by the implementer. |
|
@ -176,7 +171,6 @@ class Py3oReport(models.TransientModel): |
|
|
|
|
|
|
|
|
return tmpl_data |
|
|
return tmpl_data |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _extend_parser_context(self, context, report_xml): |
|
|
def _extend_parser_context(self, context, report_xml): |
|
|
# add default extenders |
|
|
# add default extenders |
|
|
for fct in _extender_functions.get(None, []): |
|
|
for fct in _extender_functions.get(None, []): |
|
@ -187,7 +181,6 @@ class Py3oReport(models.TransientModel): |
|
|
for fct in _extender_functions[xml_id]: |
|
|
for fct in _extender_functions[xml_id]: |
|
|
fct(report_xml, context) |
|
|
fct(report_xml, context) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _get_parser_context(self, model_instance, data): |
|
|
def _get_parser_context(self, model_instance, data): |
|
|
report_xml = self.ir_actions_report_id |
|
|
report_xml = self.ir_actions_report_id |
|
|
context = Py3oParserContext(self.env).localcontext |
|
|
context = Py3oParserContext(self.env).localcontext |
|
@ -196,7 +189,6 @@ class Py3oReport(models.TransientModel): |
|
|
self._extend_parser_context(context, report_xml) |
|
|
self._extend_parser_context(context, report_xml) |
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _postprocess_report(self, model_instance, result_path): |
|
|
def _postprocess_report(self, model_instance, result_path): |
|
|
if len(model_instance) == 1 and self.ir_actions_report_id.attachment: |
|
|
if len(model_instance) == 1 and self.ir_actions_report_id.attachment: |
|
|
with open(result_path, "rb") as f: |
|
|
with open(result_path, "rb") as f: |
|
@ -207,7 +199,6 @@ class Py3oReport(models.TransientModel): |
|
|
self.ir_actions_report_id.postprocess_pdf_report(model_instance, buffer) |
|
|
self.ir_actions_report_id.postprocess_pdf_report(model_instance, buffer) |
|
|
return result_path |
|
|
return result_path |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _create_single_report(self, model_instance, data): |
|
|
def _create_single_report(self, model_instance, data): |
|
|
""" This function to generate our py3o report |
|
|
""" This function to generate our py3o report |
|
|
""" |
|
|
""" |
|
@ -232,7 +223,6 @@ class Py3oReport(models.TransientModel): |
|
|
|
|
|
|
|
|
return self._postprocess_report(model_instance, result_path) |
|
|
return self._postprocess_report(model_instance, result_path) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _convert_single_report(self, result_path, model_instance, data): |
|
|
def _convert_single_report(self, result_path, model_instance, data): |
|
|
"""Run a command to convert to our target format""" |
|
|
"""Run a command to convert to our target format""" |
|
|
if not self.ir_actions_report_id.is_py3o_native_format: |
|
|
if not self.ir_actions_report_id.is_py3o_native_format: |
|
@ -252,7 +242,6 @@ class Py3oReport(models.TransientModel): |
|
|
) |
|
|
) |
|
|
return result_path |
|
|
return result_path |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _convert_single_report_cmd(self, result_path, model_instance, data): |
|
|
def _convert_single_report_cmd(self, result_path, model_instance, data): |
|
|
"""Return a command list suitable for use in subprocess.call""" |
|
|
"""Return a command list suitable for use in subprocess.call""" |
|
|
lo_bin = self.ir_actions_report_id.lo_bin_path |
|
|
lo_bin = self.ir_actions_report_id.lo_bin_path |
|
@ -271,7 +260,6 @@ class Py3oReport(models.TransientModel): |
|
|
result_path, |
|
|
result_path, |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _get_or_create_single_report( |
|
|
def _get_or_create_single_report( |
|
|
self, model_instance, data, existing_reports_attachment |
|
|
self, model_instance, data, existing_reports_attachment |
|
|
): |
|
|
): |
|
@ -285,7 +273,6 @@ class Py3oReport(models.TransientModel): |
|
|
return report_file |
|
|
return report_file |
|
|
return self._create_single_report(model_instance, data) |
|
|
return self._create_single_report(model_instance, data) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _zip_results(self, reports_path): |
|
|
def _zip_results(self, reports_path): |
|
|
self.ensure_one() |
|
|
self.ensure_one() |
|
|
zfname_prefix = self.ir_actions_report_id.name |
|
|
zfname_prefix = self.ir_actions_report_id.name |
|
@ -317,7 +304,6 @@ class Py3oReport(models.TransientModel): |
|
|
writer.write(merged_file) |
|
|
writer.write(merged_file) |
|
|
return merged_file_path |
|
|
return merged_file_path |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _merge_results(self, reports_path): |
|
|
def _merge_results(self, reports_path): |
|
|
self.ensure_one() |
|
|
self.ensure_one() |
|
|
filetype = self.ir_actions_report_id.py3o_filetype |
|
|
filetype = self.ir_actions_report_id.py3o_filetype |
|
@ -339,7 +325,6 @@ class Py3oReport(models.TransientModel): |
|
|
except (OSError, IOError): |
|
|
except (OSError, IOError): |
|
|
logger.error("Error when trying to remove file %s" % temporary_file) |
|
|
logger.error("Error when trying to remove file %s" % temporary_file) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def create_report(self, res_ids, data): |
|
|
def create_report(self, res_ids, data): |
|
|
""" Override this function to handle our py3o report |
|
|
""" Override this function to handle our py3o report |
|
|
""" |
|
|
""" |
|
|