[FIX] Schedule jobs even if their next time has passed.
[odoo/odoo.git] / addons / base_report_designer / base_report_designer.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
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.
12 #
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.
17 #
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/>.
20 #
21 ##############################################################################
22
23 from osv import fields,osv
24 from wizard.tiny_sxw2rml import sxw2rml
25 from StringIO import StringIO
26 from report import interface
27 import base64
28 import pooler
29 import tools
30
31 class report_xml(osv.osv):
32     _inherit = 'ir.actions.report.xml'
33
34     def sxwtorml(self,cr, uid, file_sxw,file_type):
35         '''
36         The use of this function is to get rml file from sxw file.
37         '''
38         sxwval = StringIO(base64.decodestring(file_sxw))
39         if file_type=='sxw':
40             fp = tools.file_open('normalized_oo2rml.xsl',
41                     subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
42         if file_type=='odt':
43             fp = tools.file_open('normalized_odt2rml.xsl',
44                     subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
45         
46         return  {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
47
48     def upload_report(self, cr, uid, report_id, file_sxw,file_type, context):
49         '''
50         Untested function
51         '''
52         pool = pooler.get_pool(cr.dbname)
53         sxwval = StringIO(base64.decodestring(file_sxw))
54         if file_type=='sxw':
55             fp = tools.file_open('normalized_oo2rml.xsl',
56                     subdir='addons/base_report_designer/wizard/tiny_sxw2rml')
57         if file_type=='odt':
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())),
63         })
64         cr.commit()
65         db = pooler.get_db_only(cr.dbname)
66         interface.register_all(db)
67         return True
68     def report_get(self, cr, uid, report_id, context={}):
69         report = self.browse(cr, uid, report_id, context)
70         return {
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
74         }
75 report_xml()
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
77