modifs
[odoo/odoo.git] / addons / base_report_designer / base_report_designer.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.     
19 #
20 ##############################################################################
21
22 from osv import fields,osv
23 from wizard.tiny_sxw2rml import sxw2rml
24 from StringIO import StringIO
25 from report import interface
26 import base64
27 import pooler
28 import tools
29
30 class report_xml(osv.osv):
31     _inherit = 'ir.actions.report.xml'
32
33     def sxwtorml(self,cr, uid, file_sxw,file_type):
34         '''
35         The use of this function is to get rml file from sxw file.
36         '''
37         sxwval = StringIO(base64.decodestring(file_sxw))
38         if file_type=='sxw':
39             fp = tools.file_open('normalized_oo2rml.xsl',
40                     subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
41         if file_type=='odt':
42             fp = tools.file_open('normalized_odt2rml.xsl',
43                     subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
44         
45         return  {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
46
47     def upload_report(self, cr, uid, report_id, file_sxw,file_type, context):
48         '''
49         Untested function
50         '''
51         pool = pooler.get_pool(cr.dbname)
52         sxwval = StringIO(base64.decodestring(file_sxw))
53         if file_type=='sxw':
54             fp = tools.file_open('normalized_oo2rml.xsl',
55                     subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
56         if file_type=='odt':
57             fp = tools.file_open('normalized_odt2rml.xsl',
58                     subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
59         report = pool.get('ir.actions.report.xml').write(cr, uid, [report_id], {
60             'report_sxw_content': base64.decodestring(file_sxw),
61             'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())),
62         })
63         db = pooler.get_db_only(cr.dbname)
64         interface.register_all(db)
65         return True
66     def report_get(self, cr, uid, report_id, context={}):
67         report = self.browse(cr, uid, report_id, context)
68         return {
69             'file_type' : report.report_type,
70             'report_sxw_content': report.report_sxw_content and base64.encodestring(report.report_sxw_content) or False,
71             'report_rml_content': report.report_rml_content and base64.encodestring(report.report_rml_content) or False
72         }
73 report_xml()
74 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
75