fix from Hardik Joshi
[odoo/odoo.git] / addons / base_report_designer / base_report_designer.py
1 ##############################################################################
2 #
3 # Copyright (c) 2004-2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
4 #                    Fabien Pinckaers <fp@tiny.Be>
5 #
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
11 # Service Company
12 #
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26 #
27 ##############################################################################
28
29 from osv import fields,osv
30 from wizard.tiny_sxw2rml import sxw2rml
31 from StringIO import StringIO
32 from report import interface
33 import base64
34 import pooler
35 import tools
36
37 class report_xml(osv.osv):
38         _inherit = 'ir.actions.report.xml'
39
40         def sxwtorml(self,cr, uid, file_sxw):
41                 '''
42                 The use of this function is to get rml file from sxw file.
43                 '''
44                 sxwval = StringIO(base64.decodestring(file_sxw))
45                 fp = tools.file_open('normalized_oo2rml.xsl',
46                                 subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
47                 return  {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
48
49         def upload_report(self, cr, uid, report_id, file_sxw, context):
50                 '''
51                 Untested function
52                 '''
53                 pool = pooler.get_pool(cr.dbname)
54                 sxwval = StringIO(base64.decodestring(file_sxw))
55                 fp = tools.file_open('normalized_oo2rml.xsl',
56                                 subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
57                 report = pool.get('ir.actions.report.xml').write(cr, uid, [report_id], {
58                         'report_sxw_content': base64.decodestring(file_sxw),
59                         'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))
60                 })
61                 cr.commit()
62                 db = pooler.get_db_only(cr.dbname)
63                 interface.register_all(db)
64                 return True
65         def report_get(self, cr, uid, report_id, context={}):
66                 report = self.browse(cr, uid, report_id, context)
67                 return {
68                         'report_sxw_content': report.report_sxw_content and base64.encodestring(report.report_sxw_content) or False,
69                         'report_rml_content': report.report_rml_content and base64.encodestring(report.report_rml_content) or False
70                 }
71 report_xml()