1 ##########################################################################
3 # Portions of this file are under the following copyright and license:
6 # Copyright (c) 2003-2004 Danny Brewer
7 # d29583@groovegarden.com
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 # See: http://www.gnu.org/licenses/lgpl.html
26 # and other portions are under the following copyright and license:
29 # OpenERP, Open Source Management Solution>..
30 # Copyright (C) 2004-2010 OpenERP SA (<http://openerp.com>).
32 # This program is free software: you can redistribute it and/or modify
33 # it under the terms of the GNU Affero General Public License as published by
34 # the Free Software Foundation, either version 3 of the License, or
35 # (at your option) any later version.
37 # This program is distributed in the hope that it will be useful,
38 # but WITHOUT ANY WARRANTY; without even the implied warranty of
39 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 # GNU Affero General Public License for more details.
42 # You should have received a copy of the GNU Affero General Public License
43 # along with this program. If not, see <http://www.gnu.org/licenses/>.
46 ##############################################################################
56 sys.setdefaultencoding("utf8")
57 from com.sun.star.task import XJobExecutor
58 if __name__<>"package":
60 from LoginTest import *
61 from lib.error import *
62 from lib.tools import *
63 from lib.logreport import *
69 class ExportToRML( unohelper.Base, XJobExecutor ):
70 def __init__(self,ctx):
72 self.module = "openerp_report"
75 if not loginstatus and __name__=="package":
79 doc = desktop.getCurrentComponent()
80 docinfo=doc.getDocumentInfo()
82 self.sock=RPCSession(url)
84 # Read Data from sxw file
85 tmpsxw = tempfile.mktemp('.'+"sxw")
87 if not doc.hasLocation():
88 mytype = Array(makePropertyValue("MediaType","application/vnd.sun.xml.writer"),)
89 doc.storeAsURL("file://"+tmpsxw,mytype)
90 data = read_data_from_file( get_absolute_file_path( doc.getURL()[7:] ) )
91 file_type = doc.getURL()[7:].split(".")[-1]
92 if docinfo.getUserFieldValue(2) == "":
93 ErrorDialog("Please Save this file on server","Use Send To Server Option in OpenERP Report Menu","Error")
95 filename = self.GetAFileName()
99 self.password = passwd
102 res = self.sock.execute(database, uid, self.password, 'ir.actions.report.xml', 'sxwtorml',base64.encodestring(data),file_type)
103 if res['report_rml_content']:
104 write_data_to_file( get_absolute_file_path( filename[7:] ), res['report_rml_content'] )
107 info = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
108 self.logobj.log_write('ExportToRML',LOG_ERROR, info)
109 ErrorDialog("Cannot save the file to the hard drive.", "Exception: %s." % e, "Error" )
111 def GetAFileName(self):
112 sFilePickerArgs = Array(10)
113 oFileDialog = createUnoService("com.sun.star.ui.dialogs.FilePicker")
114 oFileDialog.initialize(sFilePickerArgs)
115 oFileDialog.appendFilter("OpenERP Report File Save To ....","*.rml")
117 f_path = "OpenERP-"+ os.path.basename( tempfile.mktemp("","") ) + ".rml"
118 initPath = tempfile.gettempdir()
119 oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
120 if oUcb.exists(initPath):
121 oFileDialog.setDisplayDirectory('file://' + ( os.name == 'nt' and '/' or '' ) + initPath )
123 oFileDialog.setDefaultName(f_path )
125 sPath = oFileDialog.execute() == 1 and oFileDialog.Files[0] or None
126 oFileDialog.dispose()
129 if __name__<>"package" and __name__=="__main__":
131 elif __name__=="package":
132 g_ImplementationHelper.addImplementation( ExportToRML, "org.openoffice.openerp.report.exporttorml", ("com.sun.star.task.Job",),)
134 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: