2008-07-23 14:41:47 +00:00
# -*- encoding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
#
2008-11-03 19:18:56 +00:00
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
2008-06-16 11:00:21 +00:00
#
2008-11-03 19:18:56 +00:00
# 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 3 of the License, or
# (at your option) any later version.
2006-12-07 13:41:40 +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
# GNU General Public License for more details.
2006-12-07 13:41:40 +00:00
#
2008-11-03 19:18:56 +00:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
import wizard
import netsvc
import time
import osv
import pooler
_transaction_form = ''' <?xml version= " 1.0 " ?>
< form string = " Reconciliation " >
2008-07-22 15:11:28 +00:00
< separator string = " Reconciliation transactions " colspan = " 4 " / >
< field name = " trans_nbr " / >
< newline / >
< field name = " credit " / >
< field name = " debit " / >
< separator string = " Write-Off " colspan = " 4 " / >
< field name = " writeoff " / >
2006-12-07 13:41:40 +00:00
< / form > '''
_transaction_fields = {
2008-07-22 15:11:28 +00:00
' trans_nbr ' : { ' string ' : ' # of Transaction ' , ' type ' : ' integer ' , ' readonly ' : True } ,
' credit ' : { ' string ' : ' Credit amount ' , ' type ' : ' float ' , ' readonly ' : True } ,
' debit ' : { ' string ' : ' Debit amount ' , ' type ' : ' float ' , ' readonly ' : True } ,
' writeoff ' : { ' string ' : ' Write-Off amount ' , ' type ' : ' float ' , ' readonly ' : True } ,
2006-12-07 13:41:40 +00:00
}
2007-09-05 14:02:58 +00:00
def _trans_rec_get ( self , cr , uid , data , context = None ) :
2008-07-22 15:11:28 +00:00
pool = pooler . get_pool ( cr . dbname )
account_move_line_obj = pool . get ( ' account.move.line ' )
credit = debit = 0
account_id = False
count = 0
for line in account_move_line_obj . browse ( cr , uid , data [ ' ids ' ] , context = context ) :
if not line . reconcile_id and not line . reconcile_id . id :
count + = 1
credit + = line . credit
debit + = line . debit
account_id = line . account_id . id
return { ' trans_nbr ' : count , ' account_id ' : account_id , ' credit ' : credit , ' debit ' : debit , ' writeoff ' : debit - credit }
2007-09-05 14:02:58 +00:00
2008-01-09 17:45:52 +00:00
def _trans_rec_reconcile_partial ( self , cr , uid , data , context = None ) :
2008-07-22 15:11:28 +00:00
pool = pooler . get_pool ( cr . dbname )
account_move_line_obj = pool . get ( ' account.move.line ' )
account_move_line_obj . reconcile_partial ( cr , uid , data [ ' ids ' ] , ' manual ' , context = context )
return { }
2008-01-09 17:45:52 +00:00
2007-09-05 14:02:58 +00:00
def _trans_rec_reconcile ( self , cr , uid , data , context = None ) :
2008-07-22 15:11:28 +00:00
pool = pooler . get_pool ( cr . dbname )
account_move_line_obj = pool . get ( ' account.move.line ' )
2006-12-07 13:41:40 +00:00
2008-07-22 15:11:28 +00:00
form = data [ ' form ' ]
account_id = form . get ( ' writeoff_acc_id ' , False )
period_id = form . get ( ' period_id ' , False )
journal_id = form . get ( ' journal_id ' , False )
account_move_line_obj . reconcile ( cr , uid , data [ ' ids ' ] , ' manual ' , account_id ,
period_id , journal_id , context = context )
return { }
2006-12-07 13:41:40 +00:00
2008-01-09 17:45:52 +00:00
def _partial_check ( self , cr , uid , data , context ) :
2008-07-22 15:11:28 +00:00
if _trans_rec_get ( self , cr , uid , data , context ) [ ' writeoff ' ] == 0 :
return ' init_full '
return ' init_partial '
2006-12-07 13:41:40 +00:00
_transaction_add_form = ''' <?xml version= " 1.0 " ?>
< form string = " Information addendum " >
2008-07-22 15:11:28 +00:00
< separator string = " Write-Off Move " colspan = " 4 " / >
< field name = " journal_id " / >
< field name = " period_id " / >
< field name = " writeoff_acc_id " domain = " [( ' type ' , ' <> ' , ' view ' )] " / >
2006-12-07 13:41:40 +00:00
< / form > '''
_transaction_add_fields = {
2008-07-22 15:11:28 +00:00
' journal_id ' : { ' string ' : ' Write-Off Journal ' , ' type ' : ' many2one ' , ' relation ' : ' account.journal ' , ' required ' : True } ,
' period_id ' : { ' string ' : ' Write-Off Period ' , ' type ' : ' many2one ' , ' relation ' : ' account.period ' , ' required ' : True } ,
' writeoff_acc_id ' : { ' string ' : ' Write-Off account ' , ' type ' : ' many2one ' , ' relation ' : ' account.account ' , ' required ' : True } ,
2006-12-07 13:41:40 +00:00
}
def _trans_rec_addendum ( self , cr , uid , data , context = { } ) :
2008-07-22 15:11:28 +00:00
pool = pooler . get_pool ( cr . dbname )
ids = pool . get ( ' account.period ' ) . find ( cr , uid , context = context )
period_id = False
if len ( ids ) :
period_id = ids [ 0 ]
return { ' period_id ' : period_id }
2006-12-07 13:41:40 +00:00
class wiz_reconcile ( wizard . interface ) :
2008-07-22 15:11:28 +00:00
states = {
' init ' : {
' actions ' : [ ] ,
' result ' : { ' type ' : ' choice ' , ' next_state ' : _partial_check }
} ,
' init_full ' : {
' actions ' : [ _trans_rec_get ] ,
' result ' : { ' type ' : ' form ' , ' arch ' : _transaction_form , ' fields ' : _transaction_fields , ' state ' : [ ( ' end ' , ' Cancel ' ) , ( ' reconcile ' , ' Reconcile ' ) ] }
} ,
' init_partial ' : {
' actions ' : [ _trans_rec_get ] ,
' result ' : { ' type ' : ' form ' , ' arch ' : _transaction_form , ' fields ' : _transaction_fields , ' state ' : [ ( ' end ' , ' Cancel ' ) , ( ' addendum ' , ' Reconcile With Write-Off ' ) , ( ' partial ' , ' Partial Reconcile ' ) ] }
} ,
' addendum ' : {
' actions ' : [ _trans_rec_addendum ] ,
' result ' : { ' type ' : ' form ' , ' arch ' : _transaction_add_form , ' fields ' : _transaction_add_fields , ' state ' : [ ( ' end ' , ' Cancel ' ) , ( ' reconcile ' , ' Reconcile ' ) ] }
} ,
' reconcile ' : {
' actions ' : [ _trans_rec_reconcile ] ,
' result ' : { ' type ' : ' state ' , ' state ' : ' end ' }
} ,
' partial ' : {
' actions ' : [ _trans_rec_reconcile_partial ] ,
' result ' : { ' type ' : ' state ' , ' state ' : ' end ' }
}
}
2006-12-07 13:41:40 +00:00
wiz_reconcile ( ' account.move.line.reconcile ' )
2008-07-23 14:41:47 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: