1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from openerp_sxw2rml import sxw2rml
24 from StringIO import StringIO
25 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 = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_oo2rml.xsl'),'rb')
42 fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_odt2rml.xsl'),'rb')
43 return {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
45 def upload_report(self, cr, uid, report_id, file_sxw, file_type, context):
49 pool = pooler.get_pool(cr.dbname)
50 sxwval = StringIO(base64.decodestring(file_sxw))
52 fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_oo2rml.xsl'),'rb')
54 fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_odt2rml.xsl'),'rb')
55 report = pool.get('ir.actions.report.xml').write(cr, uid, [report_id], {
56 'report_sxw_content': base64.decodestring(file_sxw),
57 'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())),
59 db = pooler.get_db_only(cr.dbname)
60 interface.register_all(db)
63 def report_get(self, cr, uid, report_id, context={}):
64 report = self.browse(cr, uid, report_id, context)
66 'file_type' : report.report_type,
67 'report_sxw_content': report.report_sxw_content and base64.encodestring(report.report_sxw_content) or False,
68 'report_rml_content': report.report_rml_content and base64.encodestring(report.report_rml_content) or False
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: