[FIX] report_webkit: review and another series of fixes for certification of webkit report engine - see https://code.launchpad.net/~c2c/openobject-addons/trunk_webkit_addons/+merge/37829
bzr revid: odo@openerp.com-20101008143050-5fpxyt9nud4g5cg3
This commit is contained in:
parent
c10c1e6ef7
commit
f6faef13ff
|
@ -1,40 +0,0 @@
|
|||
<openerp>
|
||||
<data>
|
||||
<record id="act_report_xml_view1" model="ir.ui.view">
|
||||
<field name="name">ir.actions.report.xml.inherit1</field>
|
||||
<field name="model">ir.actions.report.xml</field>
|
||||
<field name="priority">16</field>
|
||||
<field name="inherit_id" ref="base.act_report_xml_view"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="groups_id" position="replace" >
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="act_report_xml_view" model="ir.ui.view">
|
||||
<field name="name">ir.actions.report.xml.inherit</field>
|
||||
<field name="model">ir.actions.report.xml</field>
|
||||
<field name="inherit_id" ref="base.act_report_xml_view"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="attachment_use" position="after" >
|
||||
<notebook colspan="4">
|
||||
<page string="Security">
|
||||
<field colspan="4" name="groups_id"/>
|
||||
</page>
|
||||
<page string="Webkit Setup" >
|
||||
<field name="webkit_debug" colspan="4"/>
|
||||
<field name="webkit_header" select="2"/>
|
||||
<field name="report_webkit" colspan="4"/>
|
||||
<newline/>
|
||||
<field name="report_webkit_data" colspan="4"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
<!-- <wizard string="Add Print Buttons" model="ir.actions.report.xml" name="ir.report_actions" menu="True" id="wizard_oo_report_actions" />-->
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -30,9 +30,9 @@
|
|||
##############################################################################
|
||||
|
||||
{
|
||||
"name" : "webkit report",
|
||||
"description" : """Report system base on WebKit engine (wkhtmltopd lib) that allows to do HTML2PDF reporting.
|
||||
The module structure and some is inspired of the report_openoffice module
|
||||
"name" : "Webkit Report Engine",
|
||||
"description" : """This module adds a new Report Engine based on WebKit library (wkhtmltopdf) to support reports designed in HTML + CSS.
|
||||
The module structure and some code is inspired by the report_openoffice module.
|
||||
The module allows:
|
||||
-HTML report definition
|
||||
-Multi header support
|
||||
|
@ -44,20 +44,22 @@ The module allows:
|
|||
-Book printing capabilities
|
||||
-Margins definition
|
||||
-Paper size definition
|
||||
and munch more
|
||||
and much more
|
||||
|
||||
Many header are defined per company
|
||||
Many logo are defined per company
|
||||
CSS style, header and footer body are defined in the company
|
||||
Multiple headers and logos can be defined per company.
|
||||
CSS style, header and footer body are defined per company
|
||||
|
||||
The mapper library can be found here
|
||||
The library to install can be found here
|
||||
http://code.google.com/p/wkhtmltopdf/
|
||||
The libraries are included for Linux, Mac OS X i386 and Windows 32.
|
||||
The system libraries are available for Linux, Mac OS X i386 and Windows 32.
|
||||
|
||||
A sample invoice report is defined in the report.
|
||||
You have to create the print button by calling a wizard. For more details :
|
||||
After installing the wkhtmltopdf library on the OpenERP Server machine, you need to set the
|
||||
path to the wkthtmltopdf executable file on the Company.
|
||||
|
||||
For a sample report see also the webkit_report_sample module, and this video:
|
||||
http://files.me.com/nbessi/06n92k.mov
|
||||
|
||||
|
||||
TODO :
|
||||
JavaScript support activation deactivation
|
||||
Collated and book format support
|
||||
|
@ -67,8 +69,9 @@ Web client WYSIWYG
|
|||
"version" : "0.9",
|
||||
"depends" : ["base"],
|
||||
"author" : "Camptocamp SA - NBessi",
|
||||
"init_xml" : [],
|
||||
"update_xml": [
|
||||
"category": "Reports/Webkit",
|
||||
"url": "http://http://www.camptocamp.com/",
|
||||
"data": [
|
||||
"company_view.xml",
|
||||
"header_view.xml",
|
||||
"ir_report_view.xml",
|
|
@ -52,8 +52,8 @@ class ResCompany(osv.osv):
|
|||
'html_id',
|
||||
'Available html'
|
||||
),
|
||||
'lib_path' : fields.char('Lib Path', size=264, help="Complete path for wkhtmltopdf library."),
|
||||
|
||||
'lib_path' : fields.char('Webkit Executable Path', size=264, help="Complete path to the wkhtmltopdf executable."),
|
||||
|
||||
}
|
||||
|
||||
ResCompany()
|
|
@ -7,17 +7,16 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<notebook position="inside">
|
||||
<page string="webkit Headers">
|
||||
<field name="lib_path" colspan="4"/>
|
||||
<separator string="Images" />
|
||||
<field name="header_image" colspan="4" nolabel="1"/>
|
||||
<separator string="Headers" />
|
||||
<field name="header_webkit" colspan="4" nolabel="1"/>
|
||||
<page string="Webkit">
|
||||
<field name="lib_path" colspan="4"/>
|
||||
<separator string="Images" colspan="4"/>
|
||||
<field name="header_image" colspan="4" nolabel="1"/>
|
||||
<separator string="Headers" colspan="4"/>
|
||||
<field name="header_webkit" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
</openerp>
|
||||
|
|
@ -98,7 +98,7 @@
|
|||
<field eval=""""WebKit invoice"""" name="name"/>
|
||||
</record>
|
||||
<record id="ir_property_webkitheaderdefault0" model="ir.property">
|
||||
<field name="fields_id" ref="c2c_webkit_report.field_ir_act_report_xml_webkit_header"/>
|
||||
<field name="fields_id" ref="field_ir_act_report_xml_webkit_header"/>
|
||||
<field eval=""""webkit_header_default"""" name="name"/>
|
||||
<field eval=""""ir.header_webkit,1"""" name="value"/>
|
||||
</record>
|
|
@ -38,12 +38,6 @@ import tools
|
|||
from tools.translate import _
|
||||
import os
|
||||
|
||||
def delete_report_service(name):
|
||||
"Delete the report of the known services"
|
||||
name = 'report.%s' % name
|
||||
if netsvc.Service._services.get( name, False ):
|
||||
del netsvc.Service._services
|
||||
|
||||
def register_report(name, model, tmpl_path, parser):
|
||||
"Register the report into the services"
|
||||
name = 'report.%s' % name
|
||||
|
@ -65,21 +59,7 @@ class ReportXML(osv.osv):
|
|||
if record['report_type'] == 'webkit':
|
||||
parser=rml_parse
|
||||
register_report(record['report_name'], record['model'], record['report_rml'], parser)
|
||||
return value
|
||||
|
||||
def _report_content(self, cursor, user, ids, name, arg, context=None):
|
||||
"""Ask OpenERP for Doc String ??"""
|
||||
res = {}
|
||||
for report in self.browse(cursor, user, ids, context=context):
|
||||
data = report[name + '_data']
|
||||
if not data and report[name[:-8]]:
|
||||
try:
|
||||
fp = tools.file_open(report[name[:-8]], mode='rb')
|
||||
data = fp.read()
|
||||
except:
|
||||
data = False
|
||||
res[report.id] = data
|
||||
return res
|
||||
return value
|
||||
|
||||
def unlink(self, cursor, user, ids, context=None):
|
||||
"""Delete report and unregister it"""
|
||||
|
@ -88,11 +68,14 @@ class ReportXML(osv.osv):
|
|||
trans_ids = trans_obj.search(
|
||||
cursor,
|
||||
user,
|
||||
[('type', '=', 'webkit'), ('res_id', 'in', ids)]
|
||||
[('type', '=', 'report'), ('res_id', 'in', ids)]
|
||||
)
|
||||
trans_obj.unlink(cursor, user, trans_ids)
|
||||
for record in records:
|
||||
delete_report_service(record['report_name'])
|
||||
|
||||
# Warning: we cannot unregister the services at the moment
|
||||
# because they are shared across databases. Calling a deleted
|
||||
# report will fail so it's ok.
|
||||
|
||||
records = None
|
||||
res = super(ReportXML, self).unlink(
|
||||
cursor,
|
||||
|
@ -107,23 +90,16 @@ class ReportXML(osv.osv):
|
|||
"Create report and register it"
|
||||
res = super(ReportXML, self).create(cursor, user, vals, context)
|
||||
parser=rml_parse
|
||||
try:
|
||||
register_report(
|
||||
vals['report_name'],
|
||||
vals['model'],
|
||||
vals.get('report_rml', False),
|
||||
parser
|
||||
)
|
||||
except Exception, e:
|
||||
print e
|
||||
raise osv.except_osv(
|
||||
_('Report registration error !'),
|
||||
_('Report was not registered in system !')
|
||||
)
|
||||
register_report(
|
||||
vals['report_name'],
|
||||
vals['model'],
|
||||
vals.get('report_rml', False),
|
||||
parser
|
||||
)
|
||||
return res
|
||||
|
||||
def write(self, cursor, user, ids, vals, context=None):
|
||||
"Edit report and manage it regitration"
|
||||
"Edit report and manage it registration"
|
||||
parser=rml_parse
|
||||
record = self.read(cursor, user, ids)
|
||||
if isinstance(record, list) :
|
||||
|
@ -134,33 +110,20 @@ class ReportXML(osv.osv):
|
|||
report_name = vals['report_name']
|
||||
else:
|
||||
report_name = record['report_name']
|
||||
try:
|
||||
register_report(
|
||||
report_name,
|
||||
vals.get('model', record['model']),
|
||||
vals.get('report_rml', record['report_rml']),
|
||||
parser
|
||||
)
|
||||
except Exception, e:
|
||||
print e
|
||||
raise osv.except_osv(
|
||||
_('Report registration error !'),
|
||||
_('Report was not registered in system !')
|
||||
)
|
||||
|
||||
register_report(
|
||||
report_name,
|
||||
vals.get('model', record['model']),
|
||||
vals.get('report_rml', record['report_rml']),
|
||||
parser
|
||||
)
|
||||
res = super(ReportXML, self).write(cursor, user, ids, vals, context)
|
||||
return res
|
||||
|
||||
def _report_content_inv(self, cursor, user, inid,
|
||||
name, value, arg, context=None):
|
||||
"""Ask OpenERP for Doc String ??"""
|
||||
|
||||
self.write(cursor, user, inid, {name+'_data': value}, context=context)
|
||||
|
||||
|
||||
_name = 'ir.actions.report.xml'
|
||||
_inherit = 'ir.actions.report.xml'
|
||||
_columns = {
|
||||
'webkit_header': fields.property(
|
||||
'webkit_header': fields.property(
|
||||
'ir.header_webkit',
|
||||
type='many2one',
|
||||
relation='ir.header_webkit',
|
||||
|
@ -170,12 +133,8 @@ class ReportXML(osv.osv):
|
|||
view_load=True,
|
||||
required=True
|
||||
),
|
||||
'report_webkit': fields.char(
|
||||
'WebKit HTML path',
|
||||
size=256,
|
||||
),
|
||||
'webkit_debug' : fields.boolean('Webkit debug'),
|
||||
'report_webkit_data': fields.text('WebKit HTML content'),
|
||||
'webkit_debug' : fields.boolean('Webkit debug', help="Enable the webkit engine debugger"),
|
||||
'report_webkit_data': fields.text('Webkit Template', help="This template will be used if the main report file is not found"),
|
||||
}
|
||||
|
||||
ReportXML()
|
||||
ReportXML()
|
|
@ -0,0 +1,20 @@
|
|||
<openerp>
|
||||
<data>
|
||||
<record id="act_report_xml_view" model="ir.ui.view">
|
||||
<field name="name">ir.actions.report.xml.inherit</field>
|
||||
<field name="model">ir.actions.report.xml</field>
|
||||
<field name="inherit_id" ref="base.act_report_xml_view"/>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="/form/notebook/page[@string='Security']" position="before" >
|
||||
<page string="Webkit" attrs="{'invisible':[('report_type','!=','webkit')]}">
|
||||
<field name="webkit_header"/>
|
||||
<field name="webkit_debug"/>
|
||||
<separator string="Webkit Template (used if Report File is not found)" colspan="4"/>
|
||||
<field name="report_webkit_data" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
|
@ -29,25 +29,23 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import sys
|
||||
import platform
|
||||
import commands
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
import platform
|
||||
import report
|
||||
from report.report_sxw import *
|
||||
from osv import osv
|
||||
from tools.translate import _
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
from mako.template import Template
|
||||
import pooler
|
||||
from report_helper import WebKitHelper
|
||||
|
||||
import netsvc
|
||||
import pooler
|
||||
from report_helper import WebKitHelper
|
||||
from report.report_sxw import *
|
||||
from tools.config import config
|
||||
|
||||
import commands
|
||||
logger = netsvc.Logger()
|
||||
#from report.report_sxw import report_sxw, report_rml
|
||||
from tools.translate import _
|
||||
from osv.osv import except_osv
|
||||
|
||||
class WebKitParser(report_sxw):
|
||||
"""Custom class that use webkit to render HTML reports
|
||||
|
@ -61,7 +59,6 @@ class WebKitParser(report_sxw):
|
|||
report_sxw.__init__(self, name, table, rml, parser,
|
||||
header, store)
|
||||
|
||||
|
||||
def get_lib(self, cursor, uid, company) :
|
||||
"""Return the lib wkhtml path"""
|
||||
#TODO Detect lib in system first
|
||||
|
@ -74,85 +71,82 @@ class WebKitParser(report_sxw):
|
|||
if status[0]:
|
||||
raise
|
||||
|
||||
except Exception,e:
|
||||
raise osv.except_osv(
|
||||
_('Please install wkhtmltopdf'),
|
||||
_('Please install it on you system (sudo apt-get install wkhtmltopdf) or download it from here: http://code.google.com/p/wkhtmltopdf/downloads/list')
|
||||
except Exception:
|
||||
raise except_osv(
|
||||
_('Please install wkhtmltopdf library'),
|
||||
_('Please install it on you system (sudo apt-get install wkhtmltopdf) or download it from here: http://code.google.com/p/wkhtmltopdf/downloads/list and set the path to the executable on the Company form.')
|
||||
)
|
||||
return False
|
||||
|
||||
def genreate_pdf(self, comm_path, report_xml, header, footer, html_list):
|
||||
|
||||
def generate_pdf(self, comm_path, report_xml, header, footer, html_list):
|
||||
"""Call webkit in order to generate pdf"""
|
||||
tmp_dir = tempfile.gettempdir()
|
||||
out = report_xml.name+str(time.time())+'.pdf'
|
||||
out = os.path.join(tmp_dir, out.replace(' ',''))
|
||||
files = []
|
||||
file_to_del = []
|
||||
try:
|
||||
if comm_path:
|
||||
command = [comm_path]
|
||||
else:
|
||||
command = 'wkhtmltopdf'
|
||||
|
||||
command.append('-q')
|
||||
if header :
|
||||
head_file = file( os.path.join(
|
||||
tmp_dir,
|
||||
str(time.time()) + '.head.html'
|
||||
),
|
||||
'w'
|
||||
)
|
||||
head_file.write(header)
|
||||
head_file.close()
|
||||
file_to_del.append(head_file.name)
|
||||
command.append("--header-html '%s'"%(head_file.name))
|
||||
if footer :
|
||||
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.append("--footer-html '%s'"%(foot_file.name))
|
||||
if comm_path:
|
||||
command = [comm_path]
|
||||
else:
|
||||
command = 'wkhtmltopdf'
|
||||
|
||||
if report_xml.webkit_header.margin_top :
|
||||
command.append('--margin-top %s'%(report_xml.webkit_header.margin_top))
|
||||
if report_xml.webkit_header.magrin_bottom :
|
||||
command.append('--margin-bottom %s'%(report_xml.webkit_header.magrin_bottom))
|
||||
if report_xml.webkit_header.magrin_left :
|
||||
command.append('--margin-left %s'%(report_xml.webkit_header.magrin_left))
|
||||
if report_xml.webkit_header.magrin_right :
|
||||
command.append('--margin-right %s'%(report_xml.webkit_header.magrin_right))
|
||||
if report_xml.webkit_header.orientation :
|
||||
command.append("--orientation '%s'"%(report_xml.webkit_header.orientation))
|
||||
if report_xml.webkit_header.format :
|
||||
command.append(" --page-size '%s'"%(report_xml.webkit_header.format))
|
||||
for html in html_list :
|
||||
html_file = file(os.path.join(tmp_dir, str(time.time()) + '.body.html'), 'w')
|
||||
html_file.write(html)
|
||||
html_file.close()
|
||||
file_to_del.append(html_file.name)
|
||||
command.append(html_file.name)
|
||||
command.append(out)
|
||||
generate_command = ' '.join(command)
|
||||
command.append('-q')
|
||||
if header :
|
||||
head_file = file( os.path.join(
|
||||
tmp_dir,
|
||||
str(time.time()) + '.head.html'
|
||||
),
|
||||
'w'
|
||||
)
|
||||
head_file.write(header)
|
||||
head_file.close()
|
||||
file_to_del.append(head_file.name)
|
||||
command.append("--header-html '%s'"%(head_file.name))
|
||||
if footer :
|
||||
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.append("--footer-html '%s'"%(foot_file.name))
|
||||
|
||||
if report_xml.webkit_header.margin_top :
|
||||
command.append('--margin-top %s'%(report_xml.webkit_header.margin_top))
|
||||
if report_xml.webkit_header.magrin_bottom :
|
||||
command.append('--margin-bottom %s'%(report_xml.webkit_header.magrin_bottom))
|
||||
if report_xml.webkit_header.magrin_left :
|
||||
command.append('--margin-left %s'%(report_xml.webkit_header.magrin_left))
|
||||
if report_xml.webkit_header.magrin_right :
|
||||
command.append('--margin-right %s'%(report_xml.webkit_header.magrin_right))
|
||||
if report_xml.webkit_header.orientation :
|
||||
command.append("--orientation '%s'"%(report_xml.webkit_header.orientation))
|
||||
if report_xml.webkit_header.format :
|
||||
command.append(" --page-size '%s'"%(report_xml.webkit_header.format))
|
||||
for html in html_list :
|
||||
html_file = file(os.path.join(tmp_dir, str(time.time()) + '.body.html'), 'w')
|
||||
html_file.write(html)
|
||||
html_file.close()
|
||||
file_to_del.append(html_file.name)
|
||||
command.append(html_file.name)
|
||||
command.append(out)
|
||||
generate_command = ' '.join(command)
|
||||
try:
|
||||
status = commands.getstatusoutput(generate_command)
|
||||
if status[0] :
|
||||
raise except_osv(
|
||||
_('Webkit raise an error' ),
|
||||
status[1]
|
||||
)
|
||||
except Exception:
|
||||
try:
|
||||
status = commands.getstatusoutput(generate_command)
|
||||
if status[0] :
|
||||
raise osv.except_osv(
|
||||
_('Webkit raise an error' ),
|
||||
status[1]
|
||||
)
|
||||
except Exception, exc:
|
||||
try:
|
||||
for f_to_del in file_to_del :
|
||||
os.unlink(f_to_del)
|
||||
except Exception, exc:
|
||||
pass
|
||||
except Exception, exc:
|
||||
raise exc
|
||||
for f_to_del in file_to_del :
|
||||
os.unlink(f_to_del)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
pdf = file(out).read()
|
||||
try:
|
||||
|
@ -168,11 +162,11 @@ class WebKitParser(report_sxw):
|
|||
if not lang:
|
||||
lang = 'en_US'
|
||||
self.localcontext['lang'] = lang
|
||||
|
||||
|
||||
def translate_call(self, src):
|
||||
"""Translate String."""
|
||||
ir_translation = self.pool.get('ir.translation')
|
||||
res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid, self.name, 'webkit', self.localcontext.get('lang', 'en_US'), src)
|
||||
res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid, self.name, 'report', self.localcontext.get('lang', 'en_US'), src)
|
||||
return res
|
||||
|
||||
def formatLang(self, value, digits=None, date=False, date_time=False, grouping=True, monetary=False):
|
||||
|
@ -207,10 +201,11 @@ class WebKitParser(report_sxw):
|
|||
return lang_obj.format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary)
|
||||
|
||||
# override needed to keep the attachments' storing procedure
|
||||
def create_single_pdf(self, cursor, uid, ids, data, report_xml,
|
||||
context=None):
|
||||
def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None):
|
||||
"""generate the PDF"""
|
||||
|
||||
if report_xml.report_type != 'webkit':
|
||||
return super(WebKitParser,self).create_single_pdf(self, cursor, uid, ids, data, report_xml, context=context)
|
||||
|
||||
if not context:
|
||||
context={}
|
||||
self.parser_instance = self.parser(
|
||||
|
@ -219,7 +214,7 @@ class WebKitParser(report_sxw):
|
|||
self.name2,
|
||||
context=context
|
||||
)
|
||||
|
||||
|
||||
self.pool = pooler.get_pool(cursor.dbname)
|
||||
objs = self.getObjects(cursor, uid, ids, context)
|
||||
self.parser_instance.set_context(objs, data, ids, report_xml.report_type)
|
||||
|
@ -227,22 +222,22 @@ class WebKitParser(report_sxw):
|
|||
user = self.pool.get('res.users').browse(cursor, uid, uid)
|
||||
company = user.company_id
|
||||
|
||||
|
||||
|
||||
template = False
|
||||
if report_xml.report_webkit :
|
||||
path = os.path.join(config['addons_path'], report_xml.report_webkit)
|
||||
if report_xml.report_file :
|
||||
path = os.path.join(config['addons_path'], report_xml.report_file)
|
||||
if os.path.exists(path) :
|
||||
template = file(path).read()
|
||||
if not template and report_xml.report_webkit_data :
|
||||
template = report_xml.report_webkit_data
|
||||
if not template :
|
||||
raise osv.except_osv(_('Report template not found !'), _(''))
|
||||
raise except_osv(_('Webkit Report template not found !'), _(''))
|
||||
header = report_xml.webkit_header.html
|
||||
footer = report_xml.webkit_header.footer_html
|
||||
if not header and report_xml.header:
|
||||
raise osv.except_osv(
|
||||
_('No header defined for this report header html is empty !'),
|
||||
_('look in company settings')
|
||||
raise except_osv(
|
||||
_('No header defined for this Webkit report!'),
|
||||
_('Please set a header in company settings')
|
||||
)
|
||||
if not report_xml.header :
|
||||
#I know it could be cleaner ...
|
||||
|
@ -323,70 +318,9 @@ class WebKitParser(report_sxw):
|
|||
)
|
||||
return (deb, 'html')
|
||||
bin = self.get_lib(cursor, uid, company.id)
|
||||
pdf = self.genreate_pdf(bin, report_xml, head, foot, [html])
|
||||
pdf = self.generate_pdf(bin, report_xml, head, foot, [html])
|
||||
return (pdf, 'pdf')
|
||||
|
||||
def create_source_webkit(self, cursor, uid, ids, data, report_xml, context=None):
|
||||
"""We override the create_source_webkit function in order to handle attachement
|
||||
Code taken from report openoffice. Thanks guys :) """
|
||||
if not context:
|
||||
context = {}
|
||||
pool = pooler.get_pool(cursor.dbname)
|
||||
attach = report_xml.attachment
|
||||
if attach:
|
||||
objs = self.getObjects(cursor, uid, ids, context)
|
||||
results = []
|
||||
for obj in objs:
|
||||
aname = eval(attach, {'object':obj, 'time':time})
|
||||
result = False
|
||||
if report_xml.attachment_use and aname and context.get('attachment_use', True):
|
||||
aids = pool.get('ir.attachment').search(
|
||||
cursor,
|
||||
uid,
|
||||
[
|
||||
('datas_fname','=',aname+'.pdf'),
|
||||
('res_model','=',self.table),
|
||||
('res_id','=',obj.id)
|
||||
]
|
||||
)
|
||||
if aids:
|
||||
brow_rec = pool.get('ir.attachment').browse(cursor, uid, aids[0])
|
||||
if not brow_rec.datas:
|
||||
continue
|
||||
d = base64.decodestring(brow_rec.datas)
|
||||
results.append((d,'odt'))
|
||||
continue
|
||||
result = self.create_single_pdf(cursor, uid, [obj.id], data, report_xml, context)
|
||||
try:
|
||||
if aname:
|
||||
name = aname+'.'+result[1]
|
||||
pool.get('ir.attachment').create(cursor, uid, {
|
||||
'name': aname,
|
||||
'datas': base64.encodestring(result[0]),
|
||||
'datas_fname': name,
|
||||
'res_model': self.table,
|
||||
'res_id': obj.id,
|
||||
}, context=context
|
||||
)
|
||||
cursor.commit()
|
||||
except Exception, exp:
|
||||
import traceback, sys
|
||||
tb_s = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
|
||||
netsvc.Logger().notifyChannel(
|
||||
'report',
|
||||
netsvc.LOG_ERROR,
|
||||
str(exp)
|
||||
)
|
||||
results.append(result)
|
||||
|
||||
return self.create_single_pdf(
|
||||
cursor,
|
||||
uid,
|
||||
ids,
|
||||
data,
|
||||
report_xml,
|
||||
context
|
||||
)
|
||||
|
||||
def create(self, cursor, uid, ids, data, context=None):
|
||||
"""We override the create function in order to handle generator
|
||||
|
@ -412,7 +346,7 @@ class WebKitParser(report_sxw):
|
|||
return super(WebKitParser, self).create(cursor, uid, ids, data, context)
|
||||
if report_xml.report_type != 'webkit' :
|
||||
return super(WebKitParser, self).create(cursor, uid, ids, data, context)
|
||||
fnct_ret = self.create_source_webkit(cursor, uid, ids, data, report_xml, context)
|
||||
if not fnct_ret:
|
||||
result = self.create_source_pdf(cursor, uid, ids, data, report_xml, context)
|
||||
if not result:
|
||||
return (False,False)
|
||||
return fnct_ret
|
||||
return result
|
|
@ -30,18 +30,21 @@
|
|||
##############################################################################
|
||||
|
||||
{
|
||||
"name" : "webkit report",
|
||||
"description" : """Sample webkit Invoice Report base on WebKit engine (wkhtmltopd lib) that allows to do HTML2PDF reporting.
|
||||
"name" : "Webkit Report Samples",
|
||||
"description" : """Samples for Webkit Report Engine (report_webkit module).
|
||||
|
||||
A sample invoice report is defined .
|
||||
You have to create the print button by calling a wizard. For more details :
|
||||
A sample invoice report is included in this module, as well as a wizard to
|
||||
add Webkit Report entries on any Document in the system.
|
||||
|
||||
You have to create the print buttons by calling the wizard. For more details see:
|
||||
http://files.me.com/nbessi/06n92k.mov
|
||||
""",
|
||||
"version" : "0.9",
|
||||
"depends" : ["base", "account","c2c_webkit_report"],
|
||||
"depends" : ["base", "account", "report_webkit"],
|
||||
"category": "Reports/Webkit",
|
||||
"author" : "Camptocamp SA - NBessi",
|
||||
"init_xml" : ['data.xml'],
|
||||
"update_xml": [
|
||||
"url": "http://www.camptocamp.com/",
|
||||
"data": [ 'data.xml',
|
||||
"wizard_report_actions_view.xml",
|
||||
"report_webkit_html_view.xml",
|
||||
],
|
|
@ -2,7 +2,7 @@
|
|||
<openerp>
|
||||
<data noupdate="1">
|
||||
<record id="ir_property_webkitheaderdefault0" model="ir.property">
|
||||
<field name="fields_id" ref="c2c_webkit_report.field_ir_act_report_xml_webkit_header"/>
|
||||
<field name="fields_id" ref="report_webkit.field_ir_act_report_xml_webkit_header"/>
|
||||
<field eval=""""webkit_header_default"""" name="name"/>
|
||||
<field eval=""""ir.header_webkit,1"""" name="value"/>
|
||||
</record>
|
|
@ -1,6 +1,6 @@
|
|||
# Translation of OpenERP Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * c2c_webkit_invoice
|
||||
# * report_webkit_sample
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
|
@ -15,36 +15,36 @@ msgstr ""
|
|||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: wizard_view:ir.report_actions,exist:0
|
||||
msgid "Report Action already exist for this report."
|
||||
msgstr "Report Action already exist for this report."
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: wizard_field:ir.report_actions,add,print_button:0
|
||||
msgid "Add print button"
|
||||
msgstr "Add print button"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#: model:ir.actions.report.xml,name:c2c_webkit_invoice.report_webkit_html
|
||||
#. module: report_webkit_sample
|
||||
#: model:ir.actions.report.xml,name:report_webkit_sample.report_webkit_html
|
||||
msgid "WebKit invoice"
|
||||
msgstr "facture WebKit"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#: model:ir.actions.wizard,name:c2c_webkit_invoice.wizard_oo_report_actions
|
||||
#. module: report_webkit_sample
|
||||
#: model:ir.actions.wizard,name:report_webkit_sample.wizard_oo_report_actions
|
||||
#: wizard_view:ir.report_actions,add:0
|
||||
#: wizard_view:ir.report_actions,exist:0
|
||||
msgid "Add Print Buttons"
|
||||
msgstr "Ajouter des boutons d'impression"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#: code:addons/c2c_webkit_invoice/wizard/report_actions.py:0
|
||||
#. module: report_webkit_sample
|
||||
#: code:addons/report_webkit_sample/wizard/report_actions.py:0
|
||||
#, python-format
|
||||
msgid "Client Actions Connections"
|
||||
msgstr "Actions Client Connections"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#: model:ir.module.module,description:c2c_webkit_invoice.module_meta_information
|
||||
#. module: report_webkit_sample
|
||||
#: model:ir.module.module,description:report_webkit_sample.module_meta_information
|
||||
msgid "Report system base on WebKit engine (wkhtmltopd lib) that allows to do HTML2PDF reporting.\n"
|
||||
"The module structure and some is inspired of the report_openoffice module\n"
|
||||
"The module allows:\n"
|
||||
|
@ -112,59 +112,59 @@ msgstr "Report system base on WebKit engine (wkhtmltopd lib) that allows to do H
|
|||
"Web client WYSIWYG\n"
|
||||
" "
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: help:ir.report_actions,add,print_button:0
|
||||
msgid "Add action to menu context in print button."
|
||||
msgstr "Ajouter à l'action du menu contextuel dans le bouton d'impression."
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: wizard_button:ir.report_actions,add,end:0
|
||||
msgid "_Cancel"
|
||||
msgstr "_Cancel"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#: model:ir.module.module,shortdesc:c2c_webkit_invoice.module_meta_information
|
||||
#. module: report_webkit_sample
|
||||
#: model:ir.module.module,shortdesc:report_webkit_sample.module_meta_information
|
||||
msgid "webkit report"
|
||||
msgstr "rapport webkit"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: wizard_field:ir.report_actions,add,open_action:0
|
||||
msgid "Open added action"
|
||||
msgstr "Ouvrir ajouté action"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: wizard_button:ir.report_actions,add,process:0
|
||||
msgid "_Ok"
|
||||
msgstr "_Ok"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: wizard_button:ir.report_actions,exist,end:0
|
||||
msgid "_Close"
|
||||
msgstr "_Close"
|
||||
|
||||
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:report.webkitaccount.invoice:0
|
||||
msgid "Invoice Date"
|
||||
msgstr "Date de la facture"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:report.webkitaccount.invoice:0
|
||||
msgid "QTY"
|
||||
msgstr "QTÉ"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:report.webkitaccount.invoice:0
|
||||
msgid "Unit Price"
|
||||
msgstr "Prix unitaire"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: field:report.webkitaccount.invoice:0
|
||||
msgid "Unit of Measure"
|
||||
msgstr "Unité de mesure"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: view:account.invoice:0
|
||||
#: field:account.invoice.line,invoice_line_tax_id:0
|
||||
#: model:ir.actions.act_window,name:account.action_tax_form
|
||||
|
@ -173,69 +173,69 @@ msgstr "Unité de mesure"
|
|||
msgid "Taxes"
|
||||
msgstr "Impôts"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:report.webkitaccount.invoice:0
|
||||
msgid "Price"
|
||||
msgstr "Prix"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:report.webkitaccount.invoice:0
|
||||
msgid "Tax Lines"
|
||||
msgstr "Lignes de taxe"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:report.webkitaccount.invoice:0
|
||||
msgid "Amount"
|
||||
msgstr "Montant"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:report.webkitaccount.invoice,:0
|
||||
msgid "Partner Ref."
|
||||
msgstr "Réf. partenaire"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:report.webkitaccount.invoice:0
|
||||
msgid "Invoice Ref"
|
||||
msgstr "Réf. Facture"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: field:account.invoice,amount_tax:0
|
||||
msgid "Total"
|
||||
msgstr "Total"
|
||||
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: field:account.invoice,name:0
|
||||
#: field:account.invoice.line,name:0
|
||||
msgid "Description"
|
||||
msgstr "Description"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: view:account.invoice.line:0
|
||||
#: webkit:account.invoice.tax,invoice_id:0
|
||||
msgid "Invoice Line"
|
||||
msgstr "Ligne de facture"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: field:account.analytic.line,product_id:0
|
||||
#: field:account.invoice.line,product_id:0
|
||||
#: field:account.move.line,product_id:0
|
||||
msgid "Product"
|
||||
msgstr "Produit"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: field:account.invoice,name:0
|
||||
msgid "Document"
|
||||
msgstr "Ref. document"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: webkit:account.invoice.line,discount:0
|
||||
msgid "Disc.(%)"
|
||||
msgstr "Disc.(%)"
|
||||
|
||||
#. module: c2c_webkit_invoice
|
||||
#. module: report_webkit_sample
|
||||
#: model:account.account.type,name:account.account_type_tax
|
||||
#: field:account.invoice,amount_tax:0
|
||||
#: field:account.move.line,account_tax_id:0
|
||||
msgid "Tax"
|
||||
msgstr "Taxe"
|
||||
msgstr "Taxe"
|
|
@ -13,5 +13,5 @@ class report_webkit_html(report_sxw.rml_parse):
|
|||
|
||||
report_sxw.report_sxw('report.webkitaccount.invoice',
|
||||
'account.invoice',
|
||||
'addons/c2c_webkit_invoice/report/report_webkit_html.mako',
|
||||
'addons/report_webkit_sample/report/report_webkit_html.mako',
|
||||
parser=report_webkit_html)
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<report auto="False" id="report_webkit_html" model="account.invoice" name="webkitaccount.invoice" webkit="c2c_webkit_invoice/report/report_webkit_html.mako" string="WebKit invoice" report_type="webkit" />
|
||||
<report auto="False" id="report_webkit_html" model="account.invoice" name="webkitaccount.invoice" file="report_webkit_sample/report/report_webkit_html.mako" string="WebKit invoice" report_type="webkit" />
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue