[MERGE] forward port of branch 7.0 up to 3a0af6a
[odoo/odoo.git] / addons / report_webkit / ir_report.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) 
5 # All Right Reserved
6 #
7 # Author : Nicolas Bessi (Camptocamp)
8 #
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
14 # Service Company
15 #
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.
20 #
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.
25 #
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
29 #
30 ##############################################################################
31
32 import openerp
33 from openerp.osv import fields, orm
34
35 from webkit_report import WebKitParser
36
37 class ir_actions_report_xml(orm.Model):
38     _inherit = 'ir.actions.report.xml'
39     _columns = {
40         'webkit_header': fields.property(
41             type='many2one', relation='ir.header_webkit',
42             string='Webkit Header', help="The header linked to the report",
43             required=True),
44         'webkit_debug': fields.boolean('Webkit debug',
45             help="Enable the webkit engine debugger"),
46         'report_webkit_data': fields.text('Webkit Template',
47             help="This template will be used if the main report file is not found"),
48         'precise_mode': fields.boolean('Precise Mode',
49             help="This mode allow more precise element position as each object"
50             " is printed on a separate HTML but memory and disk usage are wider.")
51     }
52
53     def _lookup_report(self, cr, name):
54         """
55         Look up a report definition.
56         """
57         import operator
58         import os
59         opj = os.path.join
60
61         # First lookup in the deprecated place, because if the report definition
62         # has not been updated, it is more likely the correct definition is there.
63         # Only reports with custom parser specified in Python are still there.
64         if 'report.' + name in openerp.report.interface.report_int._reports:
65             new_report = openerp.report.interface.report_int._reports['report.' + name]
66             if not isinstance(new_report, WebKitParser):
67                 new_report = None
68         else:
69             cr.execute("SELECT * FROM ir_act_report_xml WHERE report_name=%s and report_type=%s", (name, 'webkit'))
70             r = cr.dictfetchone()
71             if r:
72                 if r['parser']:
73                     parser = operator.attrgetter(r['parser'])(openerp.addons)
74                     kwargs = { 'parser': parser }
75                 else:
76                     kwargs = {}
77
78                 new_report = WebKitParser('report.'+r['report_name'],
79                     r['model'], opj('addons',r['report_rml'] or '/'),
80                     header=r['header'], register=False, **kwargs)
81             else:
82                 new_report = None
83
84         if new_report:
85             return new_report
86         else:
87             return super(ir_actions_report_xml, self)._lookup_report(cr, name)
88
89 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: