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 _
26 import decimal_precision as dp
28 class account_move_line_reconcile(osv.osv_memory):
30 Account move line reconcile wizard, it checks for the write off the reconcile entry or directly reconcile.
32 _name = 'account.move.line.reconcile'
33 _description = 'Account move line reconcile'
35 'trans_nbr': fields.integer('# of Transaction', readonly=True),
36 'credit': fields.float('Credit amount', readonly=True, digits_compute=dp.get_precision('Account')),
37 'debit': fields.float('Debit amount', readonly=True, digits_compute=dp.get_precision('Account')),
38 'writeoff': fields.float('Write-Off amount', readonly=True, digits_compute=dp.get_precision('Account')),
41 def default_get(self, cr, uid, fields, context=None):
42 res = super(account_move_line_reconcile, self).default_get(cr, uid, fields, context=context)
43 data = self.trans_rec_get(cr, uid, context['active_ids'], context)
44 if 'trans_nbr' in fields:
45 res.update({'trans_nbr':data['trans_nbr']})
46 if 'credit' in fields:
47 res.update({'credit':data['credit']})
49 res.update({'debit':data['debit']})
50 if 'writeoff' in fields:
51 res.update({'writeoff':data['writeoff']})
54 def trans_rec_get(self, cr, uid, ids, context=None):
55 account_move_line_obj = self.pool.get('account.move.line')
61 for line in account_move_line_obj.browse(cr, uid, context['active_ids'], context=context):
62 if not line.reconcile_id and not line.reconcile_id.id:
66 account_id = line.account_id.id
67 return {'trans_nbr': count, 'account_id': account_id, 'credit': credit, 'debit': debit, 'writeoff': debit - credit}
69 def trans_rec_addendum_writeoff(self, cr, uid, ids, context=None):
70 return self.pool.get('account.move.line.reconcile.writeoff').trans_rec_addendum(cr, uid, ids, context)
72 def trans_rec_reconcile_partial_reconcile(self, cr, uid, ids, context=None):
73 return self.pool.get('account.move.line.reconcile.writeoff').trans_rec_reconcile_partial(cr, uid, ids, context)
75 def trans_rec_reconcile_full(self, cr, uid, ids, context=None):
76 account_move_line_obj = self.pool.get('account.move.line')
77 period_obj = self.pool.get('account.period')
86 date = time.strftime('%Y-%m-%d')
87 ids = period_obj.find(cr, uid, dt=date, context=context)
90 account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id,
91 period_id, journal_id, context=context)
92 return {'type': 'ir.actions.act_window_close'}
94 account_move_line_reconcile()
96 class account_move_line_reconcile_writeoff(osv.osv_memory):
98 It opens the write off wizard form, in that user can define the journal, account, analytic account for reconcile
100 _name = 'account.move.line.reconcile.writeoff'
101 _description = 'Account move line reconcile (writeoff)'
103 'journal_id': fields.many2one('account.journal','Write-Off Journal', required=True),
104 'writeoff_acc_id': fields.many2one('account.account','Write-Off account', required=True),
105 'date_p': fields.date('Date'),
106 'comment': fields.char('Comment', size= 64, required=True),
107 'analytic_id': fields.many2one('account.analytic.account', 'Analytic Account', domain=[('parent_id', '!=', False)]),
110 'date_p': lambda *a: time.strftime('%Y-%m-%d'),
111 'comment': 'Write-off',
114 def trans_rec_addendum(self, cr, uid, ids, context=None):
115 mod_obj = self.pool.get('ir.model.data')
118 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','account_move_line_reconcile_writeoff')], context=context)
119 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
121 'name': _('Reconcile Writeoff'),
125 'res_model': 'account.move.line.reconcile.writeoff',
126 'views': [(resource_id,'form')],
127 'type': 'ir.actions.act_window',
131 def trans_rec_reconcile_partial(self, cr, uid, ids, context=None):
132 account_move_line_obj = self.pool.get('account.move.line')
135 account_move_line_obj.reconcile_partial(cr, uid, context['active_ids'], 'manual', context=context)
136 return {'type': 'ir.actions.act_window_close'}
138 def trans_rec_reconcile(self, cr, uid, ids, context=None):
139 account_move_line_obj = self.pool.get('account.move.line')
140 period_obj = self.pool.get('account.period')
143 data = self.read(cr, uid, ids,context=context)[0]
144 account_id = data['writeoff_acc_id'][0]
145 context['date_p'] = data['date_p']
146 journal_id = data['journal_id'][0]
147 context['comment'] = data['comment']
148 if data['analytic_id']:
149 context['analytic_id'] = data['analytic_id'][0]
150 if context['date_p']:
151 date = context['date_p']
153 ids = period_obj.find(cr, uid, dt=date, context=context)
157 account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id,
158 period_id, journal_id, context=context)
159 return {'type': 'ir.actions.act_window_close'}
161 account_move_line_reconcile_writeoff()
163 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: