1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from osv import fields, osv
25 from tools.translate import _
27 class account_move_line_reconcile(osv.osv_memory):
29 Account move line reconcile wizard, it checks for the write off the reconcile entry or directly reconcile.
31 _name = 'account.move.line.reconcile'
32 _description = 'Account move line reconcile'
34 'trans_nbr': fields.integer('# of Transaction', readonly=True),
35 'credit': fields.float('Credit amount', readonly=True),
36 'debit': fields.float('Debit amount', readonly=True),
37 'writeoff': fields.float('Write-Off amount', readonly=True),
40 def default_get(self, cr, uid, fields, context=None):
41 res = super(account_move_line_reconcile, self).default_get(cr, uid, fields, context=context)
42 data = self.trans_rec_get(cr, uid, context['active_ids'], context)
43 if 'trans_nbr' in fields:
44 res.update({'trans_nbr':data['trans_nbr']})
45 if 'credit' in fields:
46 res.update({'credit':data['credit']})
48 res.update({'debit':data['debit']})
49 if 'writeoff' in fields:
50 res.update({'writeoff':data['writeoff']})
53 def trans_rec_get(self, cr, uid, ids, context=None):
54 account_move_line_obj = self.pool.get('account.move.line')
60 for line in account_move_line_obj.browse(cr, uid, context['active_ids'], context=context):
61 if not line.reconcile_id and not line.reconcile_id.id:
65 account_id = line.account_id.id
66 return {'trans_nbr': count, 'account_id': account_id, 'credit': credit, 'debit': debit, 'writeoff': debit - credit}
68 def trans_rec_addendum_writeoff(self, cr, uid, ids, context=None):
69 return self.pool.get('account.move.line.reconcile.writeoff').trans_rec_addendum(cr, uid, ids, context)
71 def trans_rec_reconcile_partial_reconcile(self, cr, uid, ids, context=None):
72 return self.pool.get('account.move.line.reconcile.writeoff').trans_rec_reconcile_partial(cr, uid, ids, context)
74 def trans_rec_reconcile_full(self, cr, uid, ids, context=None):
75 account_move_line_obj = self.pool.get('account.move.line')
76 period_obj = self.pool.get('account.period')
85 date = time.strftime('%Y-%m-%d')
86 ids = period_obj.find(cr, uid, dt=date, context=context)
89 #stop the reconciliation process by partner (manual reconciliation) only if there is nothing more to reconcile for this partner
90 if 'active_ids' in context and context['active_ids']:
91 tmp_ml_id = account_move_line_obj.browse(cr, uid, context['active_ids'], context)[0]
92 partner_id = tmp_ml_id.partner_id and tmp_ml_id.partner_id.id or False
93 debit_ml_ids = account_move_line_obj.search(cr, uid, [('partner_id', '=', partner_id), ('account_id.reconcile', '=', True), ('reconcile_id', '=', False), ('debit', '>', 0)], context=context)
94 credit_ml_ids = account_move_line_obj.search(cr, uid, [('partner_id', '=', partner_id), ('account_id.reconcile', '=', True), ('reconcile_id', '=', False), ('credit', '>', 0)], context=context)
95 for ml_id in context['active_ids']:
96 if ml_id in debit_ml_ids:
97 debit_ml_ids.remove(ml_id)
98 if ml_id in credit_ml_ids:
99 credit_ml_ids.remove(ml_id)
100 if not debit_ml_ids and credit_ml_ids:
101 context.update({'stop_reconcile': True})
102 account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id,
103 period_id, journal_id, context=context)
104 return {'type': 'ir.actions.act_window_close'}
106 account_move_line_reconcile()
108 class account_move_line_reconcile_writeoff(osv.osv_memory):
110 It opens the write off wizard form, in that user can define the journal, account, analytic account for reconcile
112 _name = 'account.move.line.reconcile.writeoff'
113 _description = 'Account move line reconcile (writeoff)'
115 'journal_id': fields.many2one('account.journal','Write-Off Journal', required=True),
116 'writeoff_acc_id': fields.many2one('account.account','Write-Off account', required=True),
117 'date_p': fields.date('Date'),
118 'comment': fields.char('Comment', size= 64, required=True),
119 'analytic_id': fields.many2one('account.analytic.account', 'Analytic Account', domain=[('parent_id', '!=', False)]),
122 'date_p': lambda *a: time.strftime('%Y-%m-%d'),
123 'comment': 'Write-off',
126 def trans_rec_addendum(self, cr, uid, ids, context=None):
127 mod_obj = self.pool.get('ir.model.data')
130 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','account_move_line_reconcile_writeoff')], context=context)
131 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
133 'name': _('Reconcile Writeoff'),
137 'res_model': 'account.move.line.reconcile.writeoff',
138 'views': [(resource_id,'form')],
139 'type': 'ir.actions.act_window',
143 def trans_rec_reconcile_partial(self, cr, uid, ids, context=None):
144 account_move_line_obj = self.pool.get('account.move.line')
147 account_move_line_obj.reconcile_partial(cr, uid, context['active_ids'], 'manual', context=context)
148 return {'type': 'ir.actions.act_window_close'}
150 def trans_rec_reconcile(self, cr, uid, ids, context=None):
151 account_move_line_obj = self.pool.get('account.move.line')
152 period_obj = self.pool.get('account.period')
155 data = self.read(cr, uid, ids,context=context)[0]
156 account_id = data['writeoff_acc_id'][0]
157 context['date_p'] = data['date_p']
158 journal_id = data['journal_id'][0]
159 context['comment'] = data['comment']
160 if data['analytic_id']:
161 context['analytic_id'] = data['analytic_id'][0]
162 if context['date_p']:
163 date = context['date_p']
165 ids = period_obj.find(cr, uid, dt=date, context=context)
169 context.update({'stop_reconcile': True})
170 account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id,
171 period_id, journal_id, context=context)
172 return {'type': 'ir.actions.act_window_close'}
174 account_move_line_reconcile_writeoff()
176 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: