From 099fe5e1eab88eb1b135f4db5f6d217a805358c7 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Tue, 4 Oct 2016 09:50:16 +0200 Subject: [PATCH 1/2] Remove unicode string --- report_py3o/models/py3o_template.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report_py3o/models/py3o_template.py b/report_py3o/models/py3o_template.py index 7281f3332..5f46179de 100644 --- a/report_py3o/models/py3o_template.py +++ b/report_py3o/models/py3o_template.py @@ -11,8 +11,8 @@ class Py3oTemplate(models.Model): py3o_template_data = fields.Binary("LibreOffice template") filetype = fields.Selection( selection=[ - ('odt', u"ODF Text Document"), - ('ods', u"ODF Spreadsheet"), + ('odt', "ODF Text Document"), + ('ods', "ODF Spreadsheet"), ], string="LibreOffice Template File Type", required=True, From 439a494d40268ae2f9cc91e74ce64e69c8f88c9c Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Tue, 4 Oct 2016 09:52:00 +0200 Subject: [PATCH 2/2] [IMP] Add the possiblity to get the template from an absolute path on the server --- report_py3o/models/ir_report.py | 3 ++- report_py3o/py3o_parser.py | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/report_py3o/models/ir_report.py b/report_py3o/models/ir_report.py index 927994e3b..2f520b98f 100644 --- a/report_py3o/models/ir_report.py +++ b/report_py3o/models/ir_report.py @@ -38,7 +38,8 @@ class ReportXml(models.Model): size=128, help=( "If the user does not provide a template this will be used " - "it should be a relative path to root of YOUR module" + "it should be a relative path to root of YOUR module " + "or an absolute path on your server." )) report_type = fields.Selection(selection_add=[('py3o', "Py3o")]) diff --git a/report_py3o/py3o_parser.py b/report_py3o/py3o_parser.py index 36ed669df..ab8c41c57 100644 --- a/report_py3o/py3o_parser.py +++ b/report_py3o/py3o_parser.py @@ -88,16 +88,22 @@ class Py3oParser(report_sxw): report_obj.py3o_template_id.py3o_template_data ) - elif report_obj.py3o_template_fallback and report_obj.module: - # if the default is defined - flbk_filename = pkg_resources.resource_filename( - "openerp.addons.%s" % report_obj.module, - report_obj.py3o_template_fallback, - ) - if os.path.exists(flbk_filename): - # and it exists on the fileystem - with open(flbk_filename, 'r') as tmpl: - tmpl_data = tmpl.read() + elif report_obj.py3o_template_fallback: + tmpl_name = report_obj.py3o_template_fallback + flbk_filename = None + if report_obj.module: + # if the default is defined + flbk_filename = pkg_resources.resource_filename( + "openerp.addons.%s" % report_obj.module, + tmpl_name, + ) + elif os.path.isabs(tmpl_name): + # It is an absolute path + flbk_filename = os.path.normcase(os.path.normpath(tmpl_name)) + if flbk_filename and os.path.exists(flbk_filename): + # and it exists on the fileystem + with open(flbk_filename, 'r') as tmpl: + tmpl_data = tmpl.read() if tmpl_data is None: # if for any reason the template is not found