2006-12-07 13:41:40 +00:00
##############################################################################
#
2008-10-06 09:46:37 +00:00
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
2006-12-07 13:41:40 +00:00
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import time
import wizard
2007-05-18 14:15:35 +00:00
import pooler
2006-12-07 13:41:40 +00:00
2008-10-16 14:00:26 +00:00
period_form = ''' <?xml version= " 1.0 " ?>
2008-10-17 13:04:39 +00:00
< form string = " Select period " colspan = " 4 " >
2008-10-17 08:25:43 +00:00
< field name = " company_id " / >
< field name = " result_selection " / >
< newline / >
< field name = " fiscalyear " / >
< label colspan = " 2 " string = " (Keep empty for all open fiscal years) " align = " 0.0 " / >
< newline / >
< separator string = " Filters " colspan = " 4 " / >
2008-10-17 04:50:38 +00:00
< field name = " state " required = " True " / >
2008-07-22 15:11:28 +00:00
< newline / >
2008-10-20 07:15:25 +00:00
< group attrs = " { ' invisible ' :[( ' state ' , ' = ' , ' byperiod ' ),( ' state ' , ' = ' , ' none ' )]} " colspan = " 4 " >
2008-10-17 08:25:43 +00:00
< separator string = " Date Filter " colspan = " 4 " / >
< field name = " date1 " / >
< field name = " date2 " / >
< / group >
2008-10-20 07:15:25 +00:00
< group attrs = " { ' invisible ' :[( ' state ' , ' = ' , ' bydate ' ),( ' state ' , ' = ' , ' none ' )]} " colspan = " 4 " >
2008-10-17 08:25:43 +00:00
< separator string = " Filter on Periods " colspan = " 4 " / >
< field name = " periods " colspan = " 4 " nolabel = " 1 " / >
2008-10-20 07:15:25 +00:00
2008-10-16 14:00:26 +00:00
< / group >
2008-10-06 09:46:37 +00:00
< / form > '''
period_fields = {
2008-07-22 15:11:28 +00:00
' company_id ' : { ' string ' : ' Company ' , ' type ' : ' many2one ' , ' relation ' : ' res.company ' , ' required ' : True } ,
2008-10-17 08:25:43 +00:00
' state ' : {
' string ' : " Date/Period Filter " ,
' type ' : ' selection ' ,
' selection ' : [ ( ' bydate ' , ' By Date ' ) , ( ' byperiod ' , ' By Period ' ) , ( ' all ' , ' By Date and Period ' ) , ( ' none ' , ' No Filter ' ) ] ,
2008-10-20 07:15:25 +00:00
' default ' : lambda * a : ' all '
2008-10-17 08:25:43 +00:00
} ,
' fiscalyear ' : {
' string ' : ' Fiscal year ' , ' type ' : ' many2one ' , ' relation ' : ' account.fiscalyear ' ,
' help ' : ' Keep empty for all open fiscal year '
} ,
2008-10-16 14:00:26 +00:00
' periods ' : { ' string ' : ' Periods ' , ' type ' : ' many2many ' , ' relation ' : ' account.period ' , ' help ' : ' All periods if empty ' , ' states ' : { ' none ' : [ ( ' readonly ' , True ) ] , ' bydate ' : [ ( ' readonly ' , True ) ] } } ,
2008-10-17 08:25:43 +00:00
' result_selection ' : {
' string ' : " Partner " ,
' type ' : ' selection ' ,
' selection ' : [ ( ' customer ' , ' Receivable Accounts ' ) , ( ' supplier ' , ' Payable Accounts ' ) , ( ' all ' , ' Receivable and Payable Accounts ' ) ] ,
' required ' : True
} ,
2008-10-17 05:02:34 +00:00
' soldeinit ' : { ' string ' : " Inclure les soldes initiaux " , ' type ' : ' boolean ' } ,
2008-10-17 04:50:38 +00:00
' date1 ' : { ' string ' : ' Start date ' , ' type ' : ' date ' , ' required ' : True , ' default ' : lambda * a : time . strftime ( ' % Y-01-01 ' ) } ,
2008-10-16 14:00:26 +00:00
' date2 ' : { ' string ' : ' End date ' , ' type ' : ' date ' , ' required ' : True , ' default ' : lambda * a : time . strftime ( ' % Y- % m- %d ' ) } ,
2006-12-07 13:41:40 +00:00
}
class wizard_report ( wizard . interface ) :
2008-10-16 14:00:26 +00:00
2008-10-17 06:29:19 +00:00
def _get_defaults ( self , cr , uid , data , context ) :
2008-07-22 15:11:28 +00:00
user = pooler . get_pool ( cr . dbname ) . get ( ' res.users ' ) . browse ( cr , uid , uid , context = context )
if user . company_id :
2008-10-16 14:00:26 +00:00
company_id = user . company_id . id
2008-07-22 15:11:28 +00:00
else :
2008-10-16 14:00:26 +00:00
company_id = pooler . get_pool ( cr . dbname ) . get ( ' res.company ' ) . search ( cr , uid , [ ( ' parent_id ' , ' = ' , False ) ] ) [ 0 ]
fiscalyear_obj = pooler . get_pool ( cr . dbname ) . get ( ' account.fiscalyear ' )
periods_obj = pooler . get_pool ( cr . dbname ) . get ( ' account.period ' )
data [ ' form ' ] [ ' fiscalyear ' ] = fiscalyear_obj . find ( cr , uid )
data [ ' form ' ] [ ' periods ' ] = periods_obj . search ( cr , uid , [ ( ' fiscalyear_id ' , ' = ' , data [ ' form ' ] [ ' fiscalyear ' ] ) ] )
2008-07-22 15:11:28 +00:00
data [ ' form ' ] [ ' company_id ' ] = company_id
2008-10-06 09:46:37 +00:00
data [ ' form ' ] [ ' soldeinit ' ] = True
data [ ' form ' ] [ ' result_selection ' ] = ' all '
2008-07-22 15:11:28 +00:00
return data [ ' form ' ]
2008-10-06 09:46:37 +00:00
2008-10-17 06:29:19 +00:00
def _check_state ( self , cr , uid , data , context ) :
2008-10-16 14:00:26 +00:00
2008-10-17 13:04:39 +00:00
if data [ ' form ' ] [ ' state ' ] == ' bydate ' :
2008-10-17 04:38:19 +00:00
self . _check_date ( cr , uid , data , context )
2008-10-06 09:46:37 +00:00
return data [ ' form ' ]
2008-10-17 06:29:19 +00:00
2008-10-06 09:46:37 +00:00
def _check_date ( self , cr , uid , data , context ) :
2008-10-16 14:00:26 +00:00
2008-10-06 09:46:37 +00:00
sql = """
SELECT f . id , f . date_start , f . date_stop FROM account_fiscalyear f Where ' %s ' between f . date_start and f . date_stop """ % (data[ ' form ' ][ ' date1 ' ])
cr . execute ( sql )
res = cr . dictfetchall ( )
if res :
if ( data [ ' form ' ] [ ' date2 ' ] > res [ 0 ] [ ' date_stop ' ] or data [ ' form ' ] [ ' date2 ' ] < res [ 0 ] [ ' date_start ' ] ) :
raise wizard . except_wizard ( ' UserError ' , ' Date to must be set between ' + res [ 0 ] [ ' date_start ' ] + " and " + res [ 0 ] [ ' date_stop ' ] )
else :
return ' report '
else :
raise wizard . except_wizard ( ' UserError ' , ' Date not in a defined fiscal year ' )
2008-07-22 15:11:28 +00:00
states = {
' init ' : {
2008-10-17 06:29:19 +00:00
' actions ' : [ _get_defaults ] ,
2008-10-16 14:00:26 +00:00
' result ' : { ' type ' : ' form ' , ' arch ' : period_form , ' fields ' : period_fields , ' state ' : [ ( ' end ' , ' Cancel ' ) , ( ' report ' , ' Print ' ) ] }
2008-07-22 15:11:28 +00:00
} ,
2008-10-06 09:46:37 +00:00
2008-07-22 15:11:28 +00:00
' report ' : {
2008-10-17 06:29:19 +00:00
' actions ' : [ _check_state ] ,
2008-07-22 15:11:28 +00:00
' result ' : { ' type ' : ' print ' , ' report ' : ' account.partner.balance ' , ' state ' : ' end ' }
}
}
2006-12-07 13:41:40 +00:00
wizard_report ( ' account.partner.balance.report ' )