[REV] Last merge by AL breaks tests

bzr revid: odo@openerp.com-20120213084242-wn07hua23owewgvm
This commit is contained in:
Olivier Dony 2012-02-13 09:42:42 +01:00
parent c0c89da4b8
commit 5ecb66312c
3 changed files with 37 additions and 29 deletions

View File

@ -50,6 +50,12 @@ class ResCompany(osv.osv):
'html_id', 'html_id',
'Available html', 'Available html',
), ),
'lib_path' : fields.char('Webkit Executable Path', size=264,
help="Full path to the wkhtmltopdf executable file. "
"Version 0.9.9 is required. Install a static version "
"of the library if you experience missing header/footers "
"on Linux."),
} }
ResCompany() ResCompany()

View File

@ -8,6 +8,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<notebook position="inside"> <notebook position="inside">
<page string="Webkit"> <page string="Webkit">
<field name="lib_path" colspan="4"/>
<separator string="Images" colspan="4"/> <separator string="Images" colspan="4"/>
<field name="header_image" colspan="4" nolabel="1"/> <field name="header_image" colspan="4" nolabel="1"/>
<separator string="Headers" colspan="4"/> <separator string="Headers" colspan="4"/>

View File

@ -36,7 +36,6 @@ import report
import tempfile import tempfile
import time import time
import logging import logging
import sys
from mako.template import Template from mako.template import Template
from mako.lookup import TemplateLookup from mako.lookup import TemplateLookup
@ -72,33 +71,35 @@ class WebKitParser(report_sxw):
report_sxw.__init__(self, name, table, rml, parser, report_sxw.__init__(self, name, table, rml, parser,
header, store) header, store)
def get_lib(self, cursor, uid): def get_lib(self, cursor, uid, company) :
"""Return the lib wkhtml path""" """Return the lib wkhtml path"""
#TODO Detect lib in system first
proxy = self.pool.get('ir.config_parameter') path = self.pool.get('res.company').read(cursor, uid, company, ['lib_path',])
webkit_path = proxy.get_param(cursor, uid, 'webkit_path') path = path['lib_path']
if not path:
if not webkit_path: raise except_osv(
try: _('Wkhtmltopdf library path is not set in company'),
defpath = os.environ.get('PATH', os.defpath).split(os.pathsep) _('Please install executable on your system'+
if hasattr(sys, 'frozen'): ' (sudo apt-get install wkhtmltopdf) or download it from here:'+
defpath.append(os.getcwd()) ' http://code.google.com/p/wkhtmltopdf/downloads/list and set the'+
webkit_path = tools.which('wkhtmltopdf', path=os.pathsep.join(defpath)) ' path to the executable on the Company form.'+
except IOError: 'Minimal version is 0.9.9')
webkit_path = None )
if os.path.isabs(path) :
if webkit_path: if (os.path.exists(path) and os.access(path, os.X_OK)\
return webkit_path and os.path.basename(path).startswith('wkhtmltopdf')):
return path
raise except_osv( else:
_('Wkhtmltopdf library path is not set'), raise except_osv(
_('Please install executable on your system' \ _('Wrong Wkhtmltopdf path set in company'+
' (sudo apt-get install wkhtmltopdf) or download it from here:' \ 'Given path is not executable or path is wrong'),
' http://code.google.com/p/wkhtmltopdf/downloads/list and set the' \ 'for path %s'%(path)
' path in the ir.config_parameter with the webkit_path key.' \ )
'Minimal version is 0.9.9') else :
) raise except_osv(
_('path to Wkhtmltopdf is not absolute'),
'for path %s'%(path)
)
def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_header=False): def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_header=False):
"""Call webkit in order to generate pdf""" """Call webkit in order to generate pdf"""
if not webkit_header: if not webkit_header:
@ -294,8 +295,8 @@ class WebKitParser(report_sxw):
logger.error(msg) logger.error(msg)
raise except_osv(_('Webkit render'), msg) raise except_osv(_('Webkit render'), msg)
return (deb, 'html') return (deb, 'html')
webkit_bin = self.get_lib(cursor, uid) bin = self.get_lib(cursor, uid, company.id)
pdf = self.generate_pdf(webkit_bin, report_xml, head, foot, htmls) pdf = self.generate_pdf(bin, report_xml, head, foot, htmls)
return (pdf, 'pdf') return (pdf, 'pdf')