1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from osv import fields,osv
24 from wizard.tiny_sxw2rml import sxw2rml
25 from StringIO import StringIO
26 from report import interface
31 class report_xml(osv.osv):
32 _inherit = 'ir.actions.report.xml'
34 def sxwtorml(self,cr, uid, file_sxw,file_type):
36 The use of this function is to get rml file from sxw file.
38 sxwval = StringIO(base64.decodestring(file_sxw))
40 fp = tools.file_open('normalized_oo2rml.xsl',
41 subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
43 fp = tools.file_open('normalized_odt2rml.xsl',
44 subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
46 return {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
48 def upload_report(self, cr, uid, report_id, file_sxw,file_type, context):
52 pool = pooler.get_pool(cr.dbname)
53 sxwval = StringIO(base64.decodestring(file_sxw))
55 fp = tools.file_open('normalized_oo2rml.xsl',
56 subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
58 fp = tools.file_open('normalized_odt2rml.xsl',
59 subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
60 report = pool.get('ir.actions.report.xml').write(cr, uid, [report_id], {
61 'report_sxw_content': base64.decodestring(file_sxw),
62 'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())),
65 db = pooler.get_db_only(cr.dbname)
66 interface.register_all(db)
68 def report_get(self, cr, uid, report_id, context={}):
69 report = self.browse(cr, uid, report_id, context)
71 'file_type' : report.report_type,
72 'report_sxw_content': report.report_sxw_content and base64.encodestring(report.report_sxw_content) or False,
73 'report_rml_content': report.report_rml_content and base64.encodestring(report.report_rml_content) or False
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: