[FIX] account: Improve balance computation of bank statement for multicurrency(case...
[odoo/odoo.git] / addons / account / account_bank_statement.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22 import time
23 import netsvc
24 from osv import fields, osv
25
26 from tools.misc import currency
27 from tools.translate import _
28
29 import mx.DateTime
30 from mx.DateTime import RelativeDateTime, now, DateTime, localtime
31
32
33 class account_bank_statement(osv.osv):
34     def _default_journal_id(self, cr, uid, context={}):
35         if context.get('journal_id', False):
36             return context['journal_id']
37         return False
38
39     def _default_balance_start(self, cr, uid, context={}):
40         cr.execute('select id from account_bank_statement where journal_id=%s order by date desc limit 1', (1,))
41         res = cr.fetchone()
42         if res:
43             return self.browse(cr, uid, [res[0]], context)[0].balance_end
44         return 0.0
45
46     def _end_balance(self, cursor, user, ids, name, attr, context=None):
47         res_currency_obj = self.pool.get('res.currency')
48         res_users_obj = self.pool.get('res.users')
49
50         res = {}
51
52         company_currency_id = res_users_obj.browse(cursor, user, user,
53                 context=context).company_id.currency_id.id
54
55         statements = self.browse(cursor, user, ids, context=context)
56         for statement in statements:
57             res[statement.id] = statement.balance_start
58             currency_id = statement.currency.id
59             for line in statement.move_line_ids:
60                 if currency_id == company_currency_id:
61                     if line.debit > 0:
62                         if line.account_id.id == \
63                                 statement.journal_id.default_debit_account_id.id:
64                             res[statement.id] += line.debit
65                     else:
66                         if line.account_id.id == \
67                                 statement.journal_id.default_credit_account_id.id:
68                             res[statement.id] -= line.credit
69                 else:
70                     if line.amount_currency > 0:
71                         res[statement.id] += line.amount_currency
72
73             if statement.state == 'draft':
74                 for line in statement.line_ids:
75                     res[statement.id] += line.amount
76         for r in res:
77             res[r] = round(res[r], 2)
78         return res
79
80     def _get_period(self, cr, uid, context={}):
81         periods = self.pool.get('account.period').find(cr, uid)
82         if periods:
83             return periods[0]
84         else:
85             return False
86
87     def _currency(self, cursor, user, ids, name, args, context=None):
88         res = {}
89         res_currency_obj = self.pool.get('res.currency')
90         res_users_obj = self.pool.get('res.users')
91         default_currency = res_users_obj.browse(cursor, user,
92                 user, context=context).company_id.currency_id
93         for statement in self.browse(cursor, user, ids, context=context):
94             currency = statement.journal_id.currency
95             if not currency:
96                 currency = default_currency
97             res[statement.id] = currency.id
98         currency_names = {}
99         for currency_id, currency_name in res_currency_obj.name_get(cursor,
100                 user, [x for x in res.values()], context=context):
101             currency_names[currency_id] = currency_name
102         for statement_id in res.keys():
103             currency_id = res[statement_id]
104             res[statement_id] = (currency_id, currency_names[currency_id])
105         return res
106
107     _order = "date desc"
108     _name = "account.bank.statement"
109     _description = "Bank Statement"
110     _columns = {
111         'name': fields.char('Name', size=64, required=True, states={'confirm': [('readonly', True)]}),
112         'date': fields.date('Date', required=True,
113             states={'confirm': [('readonly', True)]}),
114         'journal_id': fields.many2one('account.journal', 'Journal', required=True,
115             states={'confirm': [('readonly', True)]}, domain=[('type', '=', 'cash')]),
116         'period_id': fields.many2one('account.period', 'Period', required=True,
117             states={'confirm':[('readonly', True)]}),
118         'balance_start': fields.float('Starting Balance', digits=(16,2),
119             states={'confirm':[('readonly',True)]}),
120         'balance_end_real': fields.float('Ending Balance', digits=(16,2),
121             states={'confirm':[('readonly', True)]}),
122         'balance_end': fields.function(_end_balance, method=True, string='Balance'),
123         'line_ids': fields.one2many('account.bank.statement.line',
124             'statement_id', 'Statement lines',
125             states={'confirm':[('readonly', True)]}),
126         'move_line_ids': fields.one2many('account.move.line', 'statement_id',
127             'Entry lines', states={'confirm':[('readonly',True)]}),
128         'state': fields.selection([('draft', 'Draft'),('confirm', 'Confirm')],
129             'State', required=True,
130             states={'confirm': [('readonly', True)]}, readonly="1"),
131         'currency': fields.function(_currency, method=True, string='Currency',
132             type='many2one', relation='res.currency'),
133     }
134
135     _defaults = {
136         'name': lambda self, cr, uid, context=None: \
137                 self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement'),
138         'date': lambda *a: time.strftime('%Y-%m-%d'),
139         'state': lambda *a: 'draft',
140         'balance_start': _default_balance_start,
141         'journal_id': _default_journal_id,
142         'period_id': _get_period,
143     }
144
145     def button_confirm(self, cr, uid, ids, context={}):
146         done = []
147         res_currency_obj = self.pool.get('res.currency')
148         res_users_obj = self.pool.get('res.users')
149         account_move_obj = self.pool.get('account.move')
150         account_move_line_obj = self.pool.get('account.move.line')
151         account_bank_statement_line_obj = \
152                 self.pool.get('account.bank.statement.line')
153
154         company_currency_id = res_users_obj.browse(cr, uid, uid,
155                 context=context).company_id.currency_id.id
156
157         for st in self.browse(cr, uid, ids, context):
158             if not st.state=='draft':
159                 continue
160
161             if not (abs(st.balance_end - st.balance_end_real) < 0.0001):
162                 raise osv.except_osv(_('Error !'),
163                         _('The statement balance is incorrect !\n') +
164                         _('The expected balance (%.2f) is different than the computed one. (%.2f)') % (st.balance_end_real, st.balance_end))
165             if (not st.journal_id.default_credit_account_id) \
166                     or (not st.journal_id.default_debit_account_id):
167                 raise osv.except_osv(_('Configuration Error !'),
168                         _('Please verify that an account is defined in the journal.'))
169
170             for line in st.move_line_ids:
171                 if line.state <> 'valid':
172                     raise osv.except_osv(_('Error !'),
173                             _('The account entries lines are not in valid state.'))
174             # for bank.statement.lines
175             # In line we get reconcile_id on bank.ste.rec.
176             # in bank stat.rec we get line_new_ids on bank.stat.rec.line
177             for move in st.line_ids:
178                 context.update({'date':move.date})
179                 move_id = account_move_obj.create(cr, uid, {
180                     'journal_id': st.journal_id.id,
181                     'period_id': st.period_id.id,
182                     'date': move.date,
183                 }, context=context)
184                 account_bank_statement_line_obj.write(cr, uid, [move.id], {
185                     'move_ids': [(4,move_id, False)]
186                 })
187                 if not move.amount:
188                     continue
189
190                 torec = []
191                 if move.amount >= 0:
192                     account_id = st.journal_id.default_credit_account_id.id
193                 else:
194                     account_id = st.journal_id.default_debit_account_id.id
195                 acc_cur = ((move.amount<=0) and st.journal_id.default_debit_account_id) or move.account_id
196                 amount = res_currency_obj.compute(cr, uid, st.currency.id,
197                         company_currency_id, move.amount, context=context,
198                         account=acc_cur)
199                 if move.reconcile_id and move.reconcile_id.line_new_ids:
200                     for newline in move.reconcile_id.line_new_ids:
201                         amount += newline.amount
202
203                 val = {
204                     'name': move.name,
205                     'date': move.date,
206                     'ref': move.ref,
207                     'move_id': move_id,
208                     'partner_id': ((move.partner_id) and move.partner_id.id) or False,
209                     'account_id': (move.account_id) and move.account_id.id,
210                     'credit': ((amount>0) and amount) or 0.0,
211                     'debit': ((amount<0) and -amount) or 0.0,
212                     'statement_id': st.id,
213                     'journal_id': st.journal_id.id,
214                     'period_id': st.period_id.id,
215                     'currency_id': st.currency.id,
216                 }
217                 
218                 amount = res_currency_obj.compute(cr, uid, st.currency.id,
219                         company_currency_id, move.amount, context=context,
220                         account=acc_cur)
221                 if st.currency.id <> company_currency_id:
222                     amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
223                                 st.currency.id, amount, context=context,
224                                 account=acc_cur)
225                     val['amount_currency'] = -amount_cur
226
227                 if move.account_id and move.account_id.currency_id and move.account_id.currency_id.id <> company_currency_id:
228                     val['currency_id'] = move.account_id.currency_id.id
229                     amount_cur = res_currency_obj.compute(cr, uid, company_currency_id,
230                             move.account_id.currency_id.id, amount, context=context,
231                             account=acc_cur)
232                     val['amount_currency'] = -amount_cur
233
234                 torec.append(account_move_line_obj.create(cr, uid, val , context=context))
235
236                 if move.reconcile_id and move.reconcile_id.line_new_ids:
237                     for newline in move.reconcile_id.line_new_ids:
238                         account_move_line_obj.create(cr, uid, {
239                             'name': newline.name or move.name,
240                             'date': move.date,
241                             'ref': move.ref,
242                             'move_id': move_id,
243                             'partner_id': ((move.partner_id) and move.partner_id.id) or False,
244                             'account_id': (newline.account_id) and newline.account_id.id,
245                             'debit': newline.amount>0 and newline.amount or 0.0,
246                             'credit': newline.amount<0 and -newline.amount or 0.0,
247                             'statement_id': st.id,
248                             'journal_id': st.journal_id.id,
249                             'period_id': st.period_id.id,
250
251                         }, context=context)
252
253                 # Fill the secondary amount/currency
254                 # if currency is not the same than the company
255                 amount_currency = False
256                 currency_id = False
257                 if st.currency.id <> company_currency_id:
258                     amount_currency = move.amount
259                     currency_id = st.currency.id
260                 account_move_line_obj.create(cr, uid, {
261                     'name': move.name,
262                     'date': move.date,
263                     'ref': move.ref,
264                     'move_id': move_id,
265                     'partner_id': ((move.partner_id) and move.partner_id.id) or False,
266                     'account_id': account_id,
267                     'credit': ((amount < 0) and -amount) or 0.0,
268                     'debit': ((amount > 0) and amount) or 0.0,
269                     'statement_id': st.id,
270                     'journal_id': st.journal_id.id,
271                     'period_id': st.period_id.id,
272                     'amount_currency': amount_currency,
273                     'currency_id': currency_id,
274                     }, context=context)
275
276                 for line in account_move_line_obj.browse(cr, uid, [x.id for x in
277                         account_move_obj.browse(cr, uid, move_id,
278                             context=context).line_id],
279                         context=context):
280                     if line.state <> 'valid':
281                         raise osv.except_osv(_('Error !'),
282                                 _('Account move line "%s" is not valid') % line.name)
283
284                 if move.reconcile_id and move.reconcile_id.line_ids:
285                     ## Search if move has already a partial reconciliation
286                     previous_partial = False
287                     for line_reconcile_move in move.reconcile_id.line_ids:
288                         if line_reconcile_move.reconcile_partial_id:
289                             previous_partial = True
290                             break
291                     ##
292                     torec += map(lambda x: x.id, move.reconcile_id.line_ids)
293                     #try:
294                     if abs(move.reconcile_amount-move.amount)<0.0001:
295
296                         writeoff_acc_id = False
297                         #There should only be one write-off account!
298                         for entry in move.reconcile_id.line_new_ids:
299                             writeoff_acc_id = entry.account_id.id
300                             break
301                         ## If we have already a partial reconciliation
302                         ## We need to make a partial reconciliation
303                         ## To add this amount to previous paid amount
304                         if previous_partial:
305                             account_move_line_obj.reconcile_partial(cr, uid, torec, 'statement', context)
306                         ## If it's the first reconciliation, we do a full reconciliation as regular
307                         else:
308                             account_move_line_obj.reconcile(cr, uid, torec, 'statement', writeoff_acc_id=writeoff_acc_id, writeoff_period_id=st.period_id.id, writeoff_journal_id=st.journal_id.id, context=context)
309
310                     else:
311                         account_move_line_obj.reconcile_partial(cr, uid, torec, 'statement', context)
312                     #except:
313                     #    raise osv.except_osv(_('Error !'), _('Unable to reconcile entry "%s": %.2f') % (move.name, move.amount))
314
315                 if st.journal_id.entry_posted:
316                     account_move_obj.write(cr, uid, [move_id], {'state':'posted'})
317             done.append(st.id)
318         self.write(cr, uid, done, {'state':'confirm'}, context=context)
319         return True
320
321     def button_cancel(self, cr, uid, ids, context={}):
322         done = []
323         for st in self.browse(cr, uid, ids, context):
324             if st.state=='draft':
325                 continue
326             ids = []
327             for line in st.line_ids:
328                 ids += [x.id for x in line.move_ids]
329             self.pool.get('account.move').unlink(cr, uid, ids, context)
330             done.append(st.id)
331         self.write(cr, uid, done, {'state':'draft'}, context=context)
332         return True
333
334     def onchange_journal_id(self, cursor, user, statement_id, journal_id, context=None):
335         if not journal_id:
336             return {'value': {'currency': False}}
337
338         account_journal_obj = self.pool.get('account.journal')
339         res_users_obj = self.pool.get('res.users')
340         res_currency_obj = self.pool.get('res.currency')
341
342         cursor.execute('SELECT balance_end_real \
343                 FROM account_bank_statement \
344                 WHERE journal_id = %s \
345                 ORDER BY date DESC,id DESC LIMIT 1', (journal_id,))
346         res = cursor.fetchone()
347         balance_start = res and res[0] or 0.0
348
349         currency_id = account_journal_obj.browse(cursor, user, journal_id,
350                 context=context).currency.id
351         if not currency_id:
352             currency_id = res_users_obj.browse(cursor, user, user,
353                     context=context).company_id.currency_id.id
354         currency = res_currency_obj.name_get(cursor, user, [currency_id],
355                 context=context)[0]
356         return {'value': {'balance_start': balance_start, 'currency': currency}}
357
358     def unlink(self, cr, uid, ids, context=None):
359         stat = self.read(cr, uid, ids, ['state'])
360         unlink_ids = []
361         for t in stat:
362             if t['state'] in ('draft'):
363                 unlink_ids.append(t['id'])
364             else:
365                 raise osv.except_osv(_('Invalid action !'), _('Cannot delete bank statement which are already confirmed !'))
366         osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
367         return True
368     
369     def copy(self, cr, uid, id, default=None, context=None):
370         if default is None:
371             default = {}
372         if context is None:
373             context = {}    
374         default = default.copy()
375         default['move_line_ids'] = []
376         return super(account_bank_statement, self).copy(cr, uid, id, default, context)
377     
378 account_bank_statement()
379
380
381 class account_bank_statement_reconcile(osv.osv):
382     _name = "account.bank.statement.reconcile"
383     _description = "Statement reconcile"
384
385     def _total_entry(self, cursor, user, ids, name, attr, context=None):
386         result = {}
387         for o in self.browse(cursor, user, ids, context=context):
388             result[o.id] = 0.0
389             for line in o.line_ids:
390                 result[o.id] += line.debit - line.credit
391         return result
392
393     def _total_new(self, cursor, user, ids, name, attr, context=None):
394         result = {}
395         for o in self.browse(cursor, user, ids, context=context):
396             result[o.id] = 0.0
397             for line in o.line_new_ids:
398                 result[o.id] += line.amount
399         return result
400
401     def _total_balance(self, cursor, user, ids, name, attr, context=None):
402         result = {}
403         for o in self.browse(cursor, user, ids, context=context):
404             result[o.id] = o.total_new - o.total_entry + o.total_amount
405         return result
406
407     def _total_amount(self, cursor, user, ids, name, attr, context=None):
408         res = {}
409         res_currency_obj = self.pool.get('res.currency')
410         res_users_obj = self.pool.get('res.users')
411
412         company_currency_id = res_users_obj.browse(cursor, user, user,
413                 context=context).company_id.currency_id.id
414         currency_id = context.get('currency_id', company_currency_id)
415
416         acc_cur = None
417         if context.get('journal_id', False) and context.get('account_id',False):
418             st =self.pool.get('account.journal').browse(cursor, user, context['journal_id'])
419             acc = self.pool.get('account.account').browse(cursor, user, context['account_id'])
420             acc_cur = (( context.get('amount',0.0)<=0) and st.default_debit_account_id) or acc
421
422         for reconcile_id in ids:
423             res[reconcile_id] = res_currency_obj.compute(cursor, user,
424                     currency_id, company_currency_id,
425                     context.get('amount', 0.0), context=context, account=acc_cur)
426         return res
427
428     def _default_amount(self, cursor, user, context=None):
429         if context is None:
430             context = {}
431         res_currency_obj = self.pool.get('res.currency')
432         res_users_obj = self.pool.get('res.users')
433
434         company_currency_id = res_users_obj.browse(cursor, user, user,
435                 context=context).company_id.currency_id.id
436         currency_id = context.get('currency_id', company_currency_id)
437
438         acc_cur = None
439         if context.get('journal_id', False) and context.get('account_id',False):
440             st =self.pool.get('account.journal').browse(cursor, user, context['journal_id'])
441             acc = self.pool.get('account.account').browse(cursor, user, context['account_id'])
442             acc_cur = (( context.get('amount',0.0)<=0) and st.default_debit_account_id) or acc
443
444         return res_currency_obj.compute(cursor, user,
445                 currency_id, company_currency_id,
446                 context.get('amount', 0.0), context=context, account=acc_cur)
447
448     def _total_currency(self, cursor, user, ids, name, attrs, context=None):
449         res = {}
450         res_users_obj = self.pool.get('res.users')
451
452         company_currency_id = res_users_obj.browse(cursor, user, user,
453                 context=context).company_id.currency_id.id
454
455         for reconcile_id in ids:
456             res[reconcile_id] = company_currency_id
457         return res
458
459     def _default_currency(self, cursor, user, context=None):
460         res_users_obj = self.pool.get('res.users')
461
462         return res_users_obj.browse(cursor, user, user,
463                 context=context).company_id.currency_id.id
464
465
466     def _total_second_amount(self, cursor, user, ids, name, attr,
467             context=None):
468         res = {}
469         for reconcile_id in ids:
470             res[reconcile_id] = context.get('amount', 0.0)
471         return res
472
473     def _total_second_currency(self, cursor, user, ids, name, attr, context=None):
474         res = {}
475         for reconcile_id in ids:
476             res[reconcile_id] = context.get('currency_id', False)
477         return res
478
479     def name_get(self, cursor, user, ids, context=None):
480         res= []
481         for o in self.browse(cursor, user, ids, context=context):
482             result = 0.0
483             res_currency = ''
484             for line in o.line_ids:
485                 if line.amount_currency and line.currency_id:
486                     result += line.amount_currency
487                     res_currency = line.currency_id.code
488                 else:
489                     result += line.debit - line.credit
490             if res_currency:
491                 res_currency = ' ' + res_currency
492             res.append((o.id, '[%.2f'% (result - o.total_new,) + res_currency + ']' ))
493         return res
494
495     _columns = {
496         'name': fields.char('Date', size=64, required=True),
497         'partner_id': fields.many2one('res.partner', 'Partner', readonly=True),
498         'line_new_ids': fields.one2many('account.bank.statement.reconcile.line',
499             'line_id', 'Write-Off'),
500         'total_entry': fields.function(_total_entry, method=True,
501             string='Total entries'),
502         'total_new': fields.function(_total_new, method=True,
503             string='Total write-off'),
504         'total_second_amount': fields.function(_total_second_amount,
505             method=True, string='Payment amount',
506             help='The amount in the currency of the journal'),
507         'total_second_currency': fields.function(_total_second_currency, method=True,
508             string='Currency', type='many2one', relation='res.currency',
509             help='The currency of the journal'),
510         'total_amount': fields.function(_total_amount, method=True,
511             string='Payment amount'),
512         'total_currency': fields.function(_total_currency, method=True,
513             string='Currency', type='many2one', relation='res.currency'),
514         'total_balance': fields.function(_total_balance, method=True,
515             string='Balance'),
516         #line_ids define in account.py
517         'statement_line': fields.one2many('account.bank.statement.line',
518              'reconcile_id', 'Bank Statement Line'),
519     }
520     _defaults = {
521         'name': lambda *a: time.strftime('%Y-%m-%d'),
522         'partner_id': lambda obj, cursor, user, context=None: \
523                 context.get('partner', False),
524         'total_amount': _default_amount,
525         'total_currency': _default_currency,
526         'total_second_amount':  lambda obj, cursor, user, context=None: \
527                 context.get('amount', 0.0),
528         'total_second_currency': lambda obj, cursor, user, context=None: \
529                 context.get('currency_id', False),
530         'total_balance': _default_amount,
531     }
532 account_bank_statement_reconcile()
533
534 class account_bank_statement_reconcile_line(osv.osv):
535     _name = "account.bank.statement.reconcile.line"
536     _description = "Statement reconcile line"
537     _columns = {
538         'name': fields.char('Description', size=64, required=True),
539         'account_id': fields.many2one('account.account', 'Account', required=True),
540         'line_id': fields.many2one('account.bank.statement.reconcile', 'Reconcile'),
541         'amount': fields.float('Amount', required=True),
542     }
543     _defaults = {
544         'name': lambda *a: 'Write-Off',
545     }
546 account_bank_statement_reconcile_line()
547
548
549 class account_bank_statement_line(osv.osv):
550
551     def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id,
552             context={}):
553         res = {'value': {}}
554         if not partner_id:
555             return res
556         line = self.browse(cursor, user, line_id)
557   
558         if not line or (line and not line[0].account_id):
559             part = self.pool.get('res.partner').browse(cursor, user, partner_id,
560                 context=context)
561             if type == 'supplier':
562                 account_id = part.property_account_payable.id
563             else:
564                 account_id =  part.property_account_receivable.id
565             res['value']['account_id'] = account_id
566
567         if not line or (line and not line[0].amount):
568             res_users_obj = self.pool.get('res.users')
569             res_currency_obj = self.pool.get('res.currency')
570             company_currency_id = res_users_obj.browse(cursor, user, user,
571                     context=context).company_id.currency_id.id
572             if not currency_id:
573                 currency_id = company_currency_id
574
575             cursor.execute('SELECT sum(debit-credit) \
576                 FROM account_move_line \
577                 WHERE (reconcile_id is null) \
578                     AND partner_id = %s \
579                     AND account_id=%s', (partner_id, account_id))
580             pgres = cursor.fetchone()
581             balance = pgres and pgres[0] or 0.0
582
583             balance = res_currency_obj.compute(cursor, user, company_currency_id,
584                 currency_id, balance, context=context)
585             res['value']['amount'] = balance
586         return res
587
588     def _reconcile_amount(self, cursor, user, ids, name, args, context=None):
589         if not ids:
590             return {}
591         res_currency_obj = self.pool.get('res.currency')
592         res_users_obj = self.pool.get('res.users')
593
594         res = {}
595         company_currency_id = res_users_obj.browse(cursor, user, user,
596                 context=context).company_id.currency_id.id
597
598         for line in self.browse(cursor, user, ids, context=context):
599             if line.reconcile_id:
600                 res[line.id] = res_currency_obj.compute(cursor, user,
601                         company_currency_id, line.statement_id.currency.id,
602                         line.reconcile_id.total_entry, context=context)
603             else:
604                 res[line.id] = 0.0
605         return res
606
607     _order = "date,name desc"
608     _name = "account.bank.statement.line"
609     _description = "Bank Statement Line"
610     _columns = {
611         'name': fields.char('Name', size=64, required=True),
612         'date': fields.date('Date', required=True),
613         'amount': fields.float('Amount'),
614         'type': fields.selection([
615             ('supplier','Supplier'),
616             ('customer','Customer'),
617             ('general','General')
618             ], 'Type', required=True),
619         'partner_id': fields.many2one('res.partner', 'Partner'),
620         'account_id': fields.many2one('account.account','Account',
621             required=True),
622         'statement_id': fields.many2one('account.bank.statement', 'Statement',
623             select=True, required=True, ondelete='cascade'),
624         'reconcile_id': fields.many2one('account.bank.statement.reconcile',
625             'Reconcile', states={'confirm':[('readonly',True)]}),
626         'move_ids': fields.many2many('account.move',
627             'account_bank_statement_line_move_rel', 'move_id','statement_id',
628             'Moves'),
629         'ref': fields.char('Ref.', size=32),
630         'note': fields.text('Notes'),
631         'reconcile_amount': fields.function(_reconcile_amount,
632             string='Amount reconciled', method=True, type='float'),
633     }
634     _defaults = {
635         'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement.line'),
636         'date': lambda *a: time.strftime('%Y-%m-%d'),
637         'type': lambda *a: 'general',
638     }
639
640 account_bank_statement_line()
641
642
643
644 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
645