2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-24 14:45:43 +00:00
|
|
|
##############################################################################
|
2010-07-14 05:36:41 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-08-24 14:45:43 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2008-08-24 14:45:43 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2008-08-24 14:45:43 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-07-14 05:36:41 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-08-24 14:45:43 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2010-07-14 05:36:41 +00:00
|
|
|
from osv import osv
|
2010-09-18 07:24:46 +00:00
|
|
|
from openerp_sxw2rml import sxw2rml
|
2008-08-24 14:45:43 +00:00
|
|
|
from StringIO import StringIO
|
|
|
|
import base64
|
|
|
|
import pooler
|
2010-09-18 07:24:46 +00:00
|
|
|
import addons
|
2011-01-06 13:15:23 +00:00
|
|
|
|
2010-07-14 05:36:41 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
class report_xml(osv.osv):
|
|
|
|
_inherit = 'ir.actions.report.xml'
|
|
|
|
|
2010-07-14 05:36:41 +00:00
|
|
|
def sxwtorml(self, cr, uid, file_sxw, file_type):
|
2008-08-24 14:45:43 +00:00
|
|
|
'''
|
|
|
|
The use of this function is to get rml file from sxw file.
|
|
|
|
'''
|
|
|
|
sxwval = StringIO(base64.decodestring(file_sxw))
|
2008-12-24 12:30:41 +00:00
|
|
|
if file_type=='sxw':
|
2010-09-18 07:24:46 +00:00
|
|
|
fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_oo2rml.xsl'),'rb')
|
2008-12-24 12:30:41 +00:00
|
|
|
if file_type=='odt':
|
2010-09-18 07:24:46 +00:00
|
|
|
fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_odt2rml.xsl'),'rb')
|
2008-08-24 14:45:43 +00:00
|
|
|
return {'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read()))}
|
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
def upload_report(self, cr, uid, report_id, file_sxw, file_type, context=None):
|
2008-08-24 14:45:43 +00:00
|
|
|
'''
|
|
|
|
Untested function
|
|
|
|
'''
|
|
|
|
pool = pooler.get_pool(cr.dbname)
|
|
|
|
sxwval = StringIO(base64.decodestring(file_sxw))
|
2008-12-24 12:30:41 +00:00
|
|
|
if file_type=='sxw':
|
2010-09-18 07:24:46 +00:00
|
|
|
fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_oo2rml.xsl'),'rb')
|
2008-12-24 11:30:37 +00:00
|
|
|
if file_type=='odt':
|
2010-09-18 07:24:46 +00:00
|
|
|
fp = open(addons.get_module_resource('base_report_designer','openerp_sxw2rml', 'normalized_odt2rml.xsl'),'rb')
|
2008-08-24 14:45:43 +00:00
|
|
|
report = pool.get('ir.actions.report.xml').write(cr, uid, [report_id], {
|
2010-07-14 05:36:41 +00:00
|
|
|
'report_sxw_content': base64.decodestring(file_sxw),
|
|
|
|
'report_rml_content': str(sxw2rml(sxwval, xsl=fp.read())),
|
2008-08-24 14:45:43 +00:00
|
|
|
})
|
2010-11-13 00:36:11 +00:00
|
|
|
pool.get('ir.actions.report.xml').register_all(cr)
|
2008-08-24 14:45:43 +00:00
|
|
|
return True
|
2010-07-14 05:36:41 +00:00
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
def report_get(self, cr, uid, report_id, context=None):
|
|
|
|
report = self.browse(cr, uid, report_id, context=context)
|
2011-01-06 13:32:04 +00:00
|
|
|
sxw_data=(report.report_sxw_content).encode("iso-8859-1", "replace")
|
|
|
|
rml_data= (report.report_rml_content).encode("iso-8859-1", "replace")
|
2008-08-24 14:45:43 +00:00
|
|
|
return {
|
2010-07-14 05:36:41 +00:00
|
|
|
'file_type' : report.report_type,
|
2011-01-06 11:56:13 +00:00
|
|
|
'report_sxw_content': report.report_sxw_content and base64.encodestring(sxw_data) or False,
|
|
|
|
'report_rml_content': report.report_rml_content and base64.encodestring(rml_data) or False
|
2008-08-24 14:45:43 +00:00
|
|
|
}
|
2010-07-14 05:36:41 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
report_xml()
|
2010-07-14 05:36:41 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|