2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2008-08-24 14:45:43 +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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-08-24 14:45:43 +00:00
#
##############################################################################
import time
import wizard
import osv
import pooler
import urllib
import base64
import tools
2009-03-06 22:18:24 +00:00
from tools . translate import _
2008-08-24 14:45:43 +00:00
intro_form = ''' <?xml version= " 1.0 " ?>
< form string = " Report designer " >
< separator string = " Report designer introduction " colspan = " 4 " / >
< field name = " text " colspan = " 4 " nolabel = " 1 " / >
< / form > '''
intro_fields = {
' text ' : {
' string ' : ' Introduction ' ,
' type ' : ' text ' ,
' readonly ' : True ,
' default ' : lambda * args : """ This system must be used with the Tiny OpenOffice plugin. If you
did not installed yet , you can find this package on :
2008-12-11 00:04:19 +00:00
http : / / www . openerp . com
2008-08-24 14:45:43 +00:00
This wizard will provide you the . SXW report that you can modify
in OpenOffice . After having modified it , you will be able to reupload
2008-12-10 22:55:43 +00:00
it to the Open ERP server .
2008-08-24 14:45:43 +00:00
""" },
' operation ' : {
' string ' : ' Operation ' ,
' type ' : ' selection ' ,
' selection ' : [
( ' create ' , ' Create a new report ' ) ,
( ' modify ' , ' Modify an existing report ' )
] ,
' size ' : 32 ,
' required ' : True ,
' default ' : lambda * args : ' create ' ,
} ,
}
get_form = ''' <?xml version= " 1.0 " ?>
< form string = " Get a report " >
< separator string = " Select your report " colspan = " 4 " / >
< field name = " report_id " / >
< / form > '''
get_fields = {
' report_id ' : {
' string ' : ' Report ' ,
' type ' : ' many2one ' ,
' relation ' : ' ir.actions.report.xml ' ,
' required ' : True ,
' domain ' : [ ( ' report_sxw_content ' , ' <> ' , False ) ] ,
} ,
}
get_form_result = ''' <?xml version= " 1.0 " ?>
< form string = " Get a report " >
< separator string = " The .SXW report " colspan = " 4 " / >
< field name = " report_id " / >
< newline / >
< field name = " file_sxw " / >
< newline / >
2008-12-10 22:55:43 +00:00
< label colspan = " 4 " string = " This is the template of your requested report. \n Save it as a .SXW file and open it with OpenOffice. \n Don ' t forget to install the Tiny OpenOffice package to modify it. \n Once it is modified, re-upload it in Open ERP using this wizard. " align = " 0.0 " / >
2008-08-24 14:45:43 +00:00
< / form > '''
get_form_fields = {
' report_id ' : {
' string ' : ' Report ' ,
' type ' : ' many2one ' ,
' relation ' : ' ir.actions.report.xml ' ,
' readonly ' : True ,
} ,
' file_sxw ' : {
' string ' : ' Your .SXW file ' ,
' type ' : ' binary ' ,
' readonly ' : True ,
}
}
send_form_result_arch = ''' <?xml version= " 1.0 " ?>
< form string = " Report modified " >
< separator string = " Report modified " colspan = " 4 " / >
< label string = " Your report has been modified. " / >
< / form > '''
send_form_result_fields = {
}
send_form_arch = ''' <?xml version= " 1.0 " ?>
< form string = " Get a report " >
< separator string = " Upload your modified report " colspan = " 4 " / >
< field name = " report_id " / >
< newline / >
< field name = " file_sxw " / >
< / form > '''
send_form_fields = {
' report_id ' : {
' string ' : ' Report ' ,
' type ' : ' many2one ' ,
' relation ' : ' ir.actions.report.xml ' ,
' required ' : True ,
' domain ' : [ ( ' report_sxw_content ' , ' <> ' , False ) ]
} ,
' file_sxw ' : {
' string ' : ' Your .SXW file ' ,
' type ' : ' binary ' ,
' required ' : True
}
}
2010-02-11 10:07:09 +00:00
rml_form_arch = ''' <?xml version= " 1.0 " ?>
< form string = " Save As " colspan = " 4 " >
< field name = " file_rml " / >
< / form >
'''
rml_form_fields = {
' file_rml ' : {
' string ' : ' Save As ' ,
' type ' : ' binary ' ,
}
}
save_rml_arch = ''' <?xml version= " 1.0 " ?>
< form string = " File saved " >
< separator string = " File saved " colspan = " 4 " / >
< label string = " Your .rml file is saved and report has been modified. " / >
< / form > '''
2008-08-24 14:45:43 +00:00
def _get_default ( obj , cursor , user , data , context ) :
2008-09-04 08:57:40 +00:00
return { }
2008-08-24 14:45:43 +00:00
class base_report_designer_modify ( wizard . interface ) :
def _upload_report_clear ( self , cr , uid , data , context ) :
return { ' file_sxw ' : False }
def _upload_report ( self , cr , uid , data , context ) :
import tiny_sxw2rml
import StringIO
pool = pooler . get_pool ( cr . dbname )
sxwval = StringIO . StringIO ( base64 . decodestring ( data [ ' form ' ] [ ' file_sxw ' ] ) )
fp = tools . file_open ( ' normalized_oo2rml.xsl ' , subdir = ' addons/base_report_designer/wizard/tiny_sxw2rml ' )
2010-02-11 10:07:09 +00:00
newrmlcontent = str ( tiny_sxw2rml . sxw2rml ( sxwval , xsl = fp . read ( ) ) )
2008-08-24 14:45:43 +00:00
report = pool . get ( ' ir.actions.report.xml ' ) . write ( cr , uid , [ data [ ' form ' ] [ ' report_id ' ] ] , {
' report_sxw_content ' : base64 . decodestring ( data [ ' form ' ] [ ' file_sxw ' ] ) ,
2010-02-11 10:07:09 +00:00
' report_rml_content ' : newrmlcontent
2008-08-24 14:45:43 +00:00
} )
2010-02-11 10:07:09 +00:00
return { ' file_rml ' : base64 . encodestring ( newrmlcontent ) }
2008-08-24 14:45:43 +00:00
def _get_report ( self , cr , uid , data , context ) :
pool = pooler . get_pool ( cr . dbname )
report = pool . get ( ' ir.actions.report.xml ' ) . browse ( cr , uid , data [ ' form ' ] [ ' report_id ' ] , context )
2008-09-04 08:57:40 +00:00
try :
return { ' file_sxw ' : base64 . encodestring ( report . report_sxw_content ) }
except :
2009-01-06 12:12:59 +00:00
raise wizard . except_wizard ( _ ( ' Error ' ) , _ ( ' Report does not contain the sxw content! ' ) )
2008-08-24 14:45:43 +00:00
states = {
' init ' : {
' actions ' : [ ] ,
' result ' : {
' type ' : ' form ' ,
' arch ' : intro_form ,
' fields ' : intro_fields ,
' state ' : [
( ' end ' , ' Cancel ' ) ,
( ' get_form ' , ' Modify a report ' )
]
}
} ,
' get_form ' : {
' actions ' : [ _get_default ] ,
' result ' : {
' type ' : ' form ' ,
' arch ' : get_form ,
' fields ' : get_fields ,
' state ' : [
( ' end ' , ' Cancel ' ) ,
( ' get_form_result ' , ' Continue ' ) ,
]
}
} ,
' get_form_result ' : {
' actions ' : [ _get_report ] ,
' result ' : {
' type ' : ' form ' ,
' arch ' : get_form_result ,
' fields ' : get_form_fields ,
' state ' : [
( ' end ' , ' Close ' ) ,
( ' send_form ' , ' Upload the modified report ' ) ,
]
}
} ,
' send_form ' : {
' actions ' : [ _upload_report_clear ] ,
' result ' : {
' type ' : ' form ' ,
' arch ' : send_form_arch ,
' fields ' : send_form_fields ,
' state ' : [
( ' end ' , ' Close ' ) ,
2010-02-11 10:07:09 +00:00
( ' save_rml_to ' , ' Update the report ' ) ,
2008-08-24 14:45:43 +00:00
]
}
} ,
2010-02-11 10:07:09 +00:00
' save_rml_to ' : {
2008-08-24 14:45:43 +00:00
' actions ' : [ _upload_report ] ,
2010-02-11 10:07:09 +00:00
' result ' : {
' type ' : ' form ' ,
' arch ' : rml_form_arch ,
' fields ' : rml_form_fields ,
' state ' : [
( ' save_rml ' , ' Save rml ' ) ,
( ' send_form_result ' , ' Skip ' ) ,
]
}
} ,
' send_form_result ' : {
' actions ' : [ ] ,
2008-08-24 14:45:43 +00:00
' result ' : {
' type ' : ' form ' ,
' arch ' : send_form_result_arch ,
' fields ' : send_form_result_fields ,
' state ' : [
( ' end ' , ' Close ' ) ,
]
}
} ,
2010-02-11 10:07:09 +00:00
' save_rml ' : {
' actions ' : [ ] ,
' result ' : {
' type ' : ' form ' ,
' arch ' : save_rml_arch , ' fields ' : { } ,
' state ' : [
( ' end ' , ' Close ' ) ,
]
}
} ,
2008-08-24 14:45:43 +00:00
}
base_report_designer_modify ( ' base_report_designer.modify ' )
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: