diff --git a/addons/report_webkit/webkit_report.py b/addons/report_webkit/webkit_report.py index 406013cef12..226c27f59bf 100644 --- a/addons/report_webkit/webkit_report.py +++ b/addons/report_webkit/webkit_report.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) +# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) # All Right Reserved # # Author : Nicolas Bessi (Camptocamp) @@ -60,12 +60,12 @@ class WebKitParser(report_sxw): """Custom class that use webkit to render HTML reports Code partially taken from report openoffice. Thanks guys :) """ - - def __init__(self, name, table, rml=False, parser=False, + + def __init__(self, name, table, rml=False, parser=False, header=True, store=False): self.parser_instance = False self.localcontext={} - report_sxw.__init__(self, name, table, rml, parser, + report_sxw.__init__(self, name, table, rml, parser, header, store) def get_lib(self, cursor, uid, company) : @@ -81,7 +81,7 @@ class WebKitParser(report_sxw): ' http://code.google.com/p/wkhtmltopdf/downloads/list and set the'+ ' path to the executable on the Company form.'+ 'Minimal version is 0.9.9') - ) + ) if os.path.isabs(path) : if (os.path.exists(path) and os.access(path, os.X_OK)\ and os.path.basename(path).startswith('wkhtmltopdf')): @@ -118,7 +118,7 @@ class WebKitParser(report_sxw): head_file = file( os.path.join( tmp_dir, str(time.time()) + '.head.html' - ), + ), 'w' ) head_file.write(header) @@ -129,14 +129,14 @@ class WebKitParser(report_sxw): foot_file = file( os.path.join( tmp_dir, str(time.time()) + '.foot.html' - ), + ), 'w' ) foot_file.write(footer) foot_file.close() file_to_del.append(foot_file.name) command.extend(['--footer-html', foot_file.name]) - + if webkit_header.margin_top : command.extend(['--margin-top', str(webkit_header.margin_top).replace(',', '.')]) if webkit_header.margin_bottom : @@ -163,7 +163,7 @@ class WebKitParser(report_sxw): status = subprocess.call(command, stderr=subprocess.PIPE) # ignore stderr if status : raise except_osv( - _('Webkit raise an error' ), + _('Webkit raise an error' ), status ) except Exception: @@ -176,8 +176,8 @@ class WebKitParser(report_sxw): os.unlink(out) return pdf - - + + def setLang(self, lang): if not lang: lang = 'en_US' @@ -189,8 +189,8 @@ class WebKitParser(report_sxw): res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid, self.name, 'report', self.localcontext.get('lang', 'en_US'), src) if not res : return src - return res - + return res + def formatLang(self, value, digits=None, date=False, date_time=False, grouping=True, monetary=False): """format using the know cursor, language from localcontext""" if digits is None: @@ -199,7 +199,7 @@ class WebKitParser(report_sxw): return '' pool_lang = self.pool.get('res.lang') lang = self.localcontext['lang'] - + lang_ids = pool_lang.search(self.parser_instance.cr, self.parser_instance.uid, [('code','=',lang)])[0] lang_obj = pool_lang.browse(self.parser_instance.cr, self.parser_instance.uid, lang_ids) @@ -225,7 +225,7 @@ class WebKitParser(report_sxw): # override needed to keep the attachments' storing procedure def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None): """generate the PDF""" - + if context is None: context={} @@ -247,7 +247,7 @@ class WebKitParser(report_sxw): if report_xml.report_file : path = addons.get_module_resource(report_xml.report_file) - if os.path.exists(path) : + if path and os.path.exists(path) : template = file(path).read() if not template and report_xml.report_webkit_data : template = report_xml.report_webkit_data @@ -266,7 +266,7 @@ class WebKitParser(report_sxw): -