From d90ead399afcab1825fc394d05f7022fead6a8e2 Mon Sep 17 00:00:00 2001 From: Amit Mendapara Date: Wed, 16 Jul 2008 20:13:01 +0530 Subject: [PATCH] Improved addons path support - fixed `xsl:import` search problem (print report) bzr revid: ame@tinyerp.com-20080716144301-x5ajq907yj2qogle --- bin/addons/__init__.py | 23 +++++++++++++++++++++-- bin/report/interface.py | 3 +-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/addons/__init__.py b/bin/addons/__init__.py index 2313d9ccf99..2a9b947f985 100644 --- a/bin/addons/__init__.py +++ b/bin/addons/__init__.py @@ -157,10 +157,29 @@ def get_module_resource(module, *args): """ return opj(get_module_path(module), *args) -def get_report_resource(resource): - """Return the full path of the given report resource (addons/hr/reports/timesheet.xsl') +def get_report_resource(resource, base=None): + """Return the full path of the given report resource. + + >>> + >>> get_report_resource('addons/hr/reports/timesheet.xsl') + >>> get_report_resource('../../base/reports/rml_template.xsl', '/path/to/addons/hr/reports') + >>> """ + if base: + # default location + fname = os.path.normpath(os.path.join(base, resource)) + if os.path.exists(fname): + return fname + + # check in base location + base = base.replace(ad, _ad) + fname = os.path.normpath(os.path.join(base, resource)) + if os.path.exists(fname): + return fname + + assert os.path.exists(fname), 'File does not exist: %s' % fname + fname = os.path.join(os.path.dirname(ad), resource) if os.path.exists(fname): return fname diff --git a/bin/report/interface.py b/bin/report/interface.py index 7623d21a59a..51c2ffdf23f 100644 --- a/bin/report/interface.py +++ b/bin/report/interface.py @@ -153,8 +153,7 @@ class report_rml(report_int): if child.name == 'import': if child.hasProp('href'): file = child.prop('href') - child.setProp('href', urllib.quote(str( - os.path.normpath(os.path.join(xsl_path, file))))) + child.setProp('href', urllib.quote(str(addons.get_report_resource(file, base=xsl_path)))) #TODO: get all the translation in one query. That means we have to: # * build a list of items to translate,