[MERGE] forward port of branch 7.0 up to 3a0af6a
[odoo/odoo.git] / addons / report_webkit / convert.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 from openerp.tools import convert
33
34 original_xml_import = convert.xml_import
35
36 class WebkitXMLImport(original_xml_import):
37
38     # Override of xml import in order to add webkit_header tag in report tag.
39     # As discussed with the R&D Team,  the current XML processing API does
40     # not offer enough flexibity to do it in a cleaner way.
41     # The solution is not meant to be long term solution, but at least
42     # allows chaining of several overrides of the _tag_report method,
43     # and does not require a copy/paste of the original code.
44     def _tag_report(self, cr, rec, data_node=None):
45         report_id = super(WebkitXMLImport, self)._tag_report(cr, rec, data_node)
46         if rec.get('report_type') == 'webkit':
47             header = rec.get('webkit_header')
48             if header:
49                 if header in ('False', '0', 'None'):
50                     webkit_header_id = False
51                 else:
52                     webkit_header_id = self.id_get(cr, header)
53                 self.pool.get('ir.actions.report.xml').write(cr, self.uid,
54                     report_id, {'webkit_header': webkit_header_id})
55         return report_id
56
57 convert.xml_import = WebkitXMLImport