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 openerp.osv import fields, osv
25 from openerp.tools.translate import _
26 from openerp.tools.float_utils import float_round
27 import openerp.addons.decimal_precision as dp
29 class account_move_line_reconcile(osv.osv_memory):
31 Account move line reconcile wizard, it checks for the write off the reconcile entry or directly reconcile.
33 _name = 'account.move.line.reconcile'
34 _description = 'Account move line reconcile'
36 'trans_nbr': fields.integer('# of Transaction', readonly=True),
37 'credit': fields.float('Credit amount', readonly=True, digits_compute=dp.get_precision('Account')),
38 'debit': fields.float('Debit amount', readonly=True, digits_compute=dp.get_precision('Account')),
39 'writeoff': fields.float('Write-Off amount', readonly=True, digits_compute=dp.get_precision('Account')),
42 def default_get(self, cr, uid, fields, context=None):
43 res = super(account_move_line_reconcile, self).default_get(cr, uid, fields, context=context)
44 data = self.trans_rec_get(cr, uid, context['active_ids'], context)
45 if 'trans_nbr' in fields:
46 res.update({'trans_nbr':data['trans_nbr']})
47 if 'credit' in fields:
48 res.update({'credit':data['credit']})
50 res.update({'debit':data['debit']})
51 if 'writeoff' in fields:
52 res.update({'writeoff':data['writeoff']})
55 def trans_rec_get(self, cr, uid, ids, context=None):
56 account_move_line_obj = self.pool.get('account.move.line')
62 for line in account_move_line_obj.browse(cr, uid, context['active_ids'], context=context):
63 if not line.reconcile_id and not line.reconcile_id.id:
67 account_id = line.account_id.id
68 precision = self.pool['decimal.precision'].precision_get(cr, uid, 'Account')
69 writeoff = float_round(debit-credit, precision_digits=precision)
70 credit = float_round(credit, precision_digits=precision)
71 debit = float_round(debit, precision_digits=precision)
72 return {'trans_nbr': count, 'account_id': account_id, 'credit': credit, 'debit': debit, 'writeoff': writeoff}
74 def trans_rec_addendum_writeoff(self, cr, uid, ids, context=None):
75 return self.pool.get('account.move.line.reconcile.writeoff').trans_rec_addendum(cr, uid, ids, context)
77 def trans_rec_reconcile_partial_reconcile(self, cr, uid, ids, context=None):
78 return self.pool.get('account.move.line.reconcile.writeoff').trans_rec_reconcile_partial(cr, uid, ids, context)
80 def trans_rec_reconcile_full(self, cr, uid, ids, context=None):
81 account_move_line_obj = self.pool.get('account.move.line')
82 period_obj = self.pool.get('account.period')
91 date = time.strftime('%Y-%m-%d')
92 ids = period_obj.find(cr, uid, dt=date, context=context)
95 account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id,
96 period_id, journal_id, context=context)
97 return {'type': 'ir.actions.act_window_close'}
100 class account_move_line_reconcile_writeoff(osv.osv_memory):
102 It opens the write off wizard form, in that user can define the journal, account, analytic account for reconcile
104 _name = 'account.move.line.reconcile.writeoff'
105 _description = 'Account move line reconcile (writeoff)'
107 'journal_id': fields.many2one('account.journal','Write-Off Journal', required=True),
108 'writeoff_acc_id': fields.many2one('account.account','Write-Off account', required=True),
109 'date_p': fields.date('Date'),
110 'comment': fields.char('Comment', required=True),
111 'analytic_id': fields.many2one('account.analytic.account', 'Analytic Account', domain=[('parent_id', '!=', False)]),
114 'date_p': lambda *a: time.strftime('%Y-%m-%d'),
115 'comment': _('Write-off'),
118 def trans_rec_addendum(self, cr, uid, ids, context=None):
119 mod_obj = self.pool.get('ir.model.data')
122 model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','account_move_line_reconcile_writeoff')], context=context)
123 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
125 'name': _('Reconcile Writeoff'),
129 'res_model': 'account.move.line.reconcile.writeoff',
130 'views': [(resource_id,'form')],
131 'type': 'ir.actions.act_window',
135 def trans_rec_reconcile_partial(self, cr, uid, ids, context=None):
136 account_move_line_obj = self.pool.get('account.move.line')
139 account_move_line_obj.reconcile_partial(cr, uid, context['active_ids'], 'manual', context=context)
140 return {'type': 'ir.actions.act_window_close'}
142 def trans_rec_reconcile(self, cr, uid, ids, context=None):
143 context = dict(context or {})
144 account_move_line_obj = self.pool.get('account.move.line')
145 period_obj = self.pool.get('account.period')
148 data = self.read(cr, uid, ids,context=context)[0]
149 account_id = data['writeoff_acc_id'][0]
150 context['date_p'] = data['date_p']
151 journal_id = data['journal_id'][0]
152 context['comment'] = data['comment']
153 if data['analytic_id']:
154 context['analytic_id'] = data['analytic_id'][0]
155 if context['date_p']:
156 date = context['date_p']
157 ids = period_obj.find(cr, uid, dt=date, context=context)
161 account_move_line_obj.reconcile(cr, uid, context['active_ids'], 'manual', account_id,
162 period_id, journal_id, context=context)
163 return {'type': 'ir.actions.act_window_close'}
166 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: