2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2006-12-07 13:41:40 +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-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
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.
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
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2006-12-07 13:41:40 +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/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
import wizard
import netsvc
import time
import osv
import pooler
2009-11-03 05:17:10 +00:00
from datetime import datetime
from tools . translate import _
2006-12-07 13:41:40 +00:00
_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 )
2009-11-02 08:40:00 +00:00
context [ ' date_p ' ] = form . get ( ' date_p ' , False )
date = False
if context [ ' date_p ' ] :
2009-11-03 05:17:10 +00:00
date = datetime . strptime ( context [ ' date_p ' ] , ' % Y- % m- %d ' )
2009-11-02 08:40:00 +00:00
ids = pool . get ( ' account.period ' ) . find ( cr , uid , dt = date , context = context )
period_id = False
if len ( ids ) :
period_id = ids [ 0 ]
2008-07-22 15:11:28 +00:00
journal_id = form . get ( ' journal_id ' , False )
2009-11-02 08:40:00 +00:00
context [ ' comment ' ] = form . get ( ' comment ' , False )
context [ ' analytic_id ' ] = form . get ( ' analytic_id ' , False )
2008-07-22 15:11:28 +00:00
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 = " writeoff_acc_id " domain = " [( ' type ' , ' <> ' , ' view ' )] " / >
2009-11-02 08:40:00 +00:00
< field name = " date_p " / >
< field name = " comment " / >
< separator string = " Analytic " colspan = " 4 " / >
< field name = " analytic_id " / >
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 } ,
' writeoff_acc_id ' : { ' string ' : ' Write-Off account ' , ' type ' : ' many2one ' , ' relation ' : ' account.account ' , ' required ' : True } ,
2009-11-02 08:40:00 +00:00
' date_p ' : { ' string ' : ' Date ' , ' type ' : ' date ' } ,
2009-11-03 05:19:12 +00:00
' comment ' : { ' string ' : ' Comment ' , ' type ' : ' char ' , ' size ' : 64 , ' required ' : True } ,
2009-11-02 08:40:00 +00:00
' analytic_id ' : { ' string ' : ' Analytic Account ' , ' type ' : ' many2one ' , ' relation ' : ' account.analytic.account ' } ,
2006-12-07 13:41:40 +00:00
}
def _trans_rec_addendum ( self , cr , uid , data , context = { } ) :
2009-11-02 08:40:00 +00:00
date_p = time . strftime ( ' % Y- % m- %d ' )
return { ' date_p ' : date_p , ' comment ' : _ ( ' Write-Off ' ) }
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: