1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
7 # Author : Nicolas Bessi (Camptocamp)
9 # WARNING: This program as such is intended to be used by professional
10 # programmers who take the whole responsability of assessing all potential
11 # consequences resulting from its eventual inadequacies and bugs
12 # End users who are looking for a ready-to-use solution with commercial
13 # garantees and support are strongly adviced to contract a Free Software
16 # This program is Free Software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation; either version 2
19 # of the License, or (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 ##############################################################################
32 from osv import osv, fields
34 from webkit_report import WebKitParser
35 from report.report_sxw import rml_parse
37 def register_report(name, model, tmpl_path, parser=rml_parse):
38 "Register the report into the services"
39 name = 'report.%s' % name
40 if netsvc.Service._services.get(name, False):
41 service = netsvc.Service._services[name]
42 if isinstance(service, WebKitParser):
43 #already instantiated properly, skip it
45 if hasattr(service, 'parser'):
46 parser = service.parser
47 del netsvc.Service._services[name]
48 WebKitParser(name, model, tmpl_path, parser=parser)
51 class ReportXML(osv.osv):
53 def __init__(self, pool, cr):
54 super(ReportXML, self).__init__(pool, cr)
56 def register_all(self,cursor):
57 value = super(ReportXML, self).register_all(cursor)
58 cursor.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'webkit'")
59 records = cursor.dictfetchall()
60 for record in records:
61 register_report(record['report_name'], record['model'], record['report_rml'])
64 def unlink(self, cursor, user, ids, context=None):
65 """Delete report and unregister it"""
66 trans_obj = self.pool.get('ir.translation')
67 trans_ids = trans_obj.search(
70 [('type', '=', 'report'), ('res_id', 'in', ids)]
72 trans_obj.unlink(cursor, user, trans_ids)
74 # Warning: we cannot unregister the services at the moment
75 # because they are shared across databases. Calling a deleted
76 # report will fail so it's ok.
78 res = super(ReportXML, self).unlink(
86 def create(self, cursor, user, vals, context=None):
87 "Create report and register it"
88 res = super(ReportXML, self).create(cursor, user, vals, context)
89 if vals.get('report_type','') == 'webkit':
90 # I really look forward to virtual functions :S
94 vals.get('report_rml', False)
98 def write(self, cr, uid, ids, vals, context=None):
99 "Edit report and manage it registration"
100 if isinstance(ids, (int, long)):
102 for rep in self.browse(cr, uid, ids, context=context):
103 if rep.report_type != 'webkit':
105 if vals.get('report_name', False) and \
106 vals['report_name'] != rep.report_name:
107 report_name = vals['report_name']
109 report_name = rep.report_name
113 vals.get('model', rep.model),
114 vals.get('report_rml', rep.report_rml)
116 res = super(ReportXML, self).write(cr, uid, ids, vals, context)
119 _name = 'ir.actions.report.xml'
120 _inherit = 'ir.actions.report.xml'
122 'webkit_header': fields.property(
125 relation='ir.header_webkit',
126 string='WebKit Header',
127 help="The header linked to the report",
132 'webkit_debug' : fields.boolean('Webkit debug', help="Enable the webkit engine debugger"),
133 'report_webkit_data': fields.text('Webkit Template', help="This template will be used if the main report file is not found"),