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 ##############################################################################
22 from openerp.osv import osv
23 from openerp.tools.translate import _
25 class account_move_line(osv.osv):
26 _inherit = "account.move.line"
28 def line2bank(self, cr, uid, ids, payment_type=None, context=None):
30 Try to return for each Ledger Posting line a corresponding bank
31 account according to the payment type. This work using one of
32 the bank of the partner defined on the invoice eventually
33 associated to the line.
34 Return the first suitable bank for the corresponding partner.
36 payment_mode_obj = self.pool.get('payment.mode')
40 bank_type = payment_mode_obj.suitable_bank_types(cr, uid, payment_type,
42 for line in self.browse(cr, uid, ids, context=context):
43 line2bank[line.id] = False
44 if line.invoice and line.invoice.partner_bank_id:
45 line2bank[line.id] = line.invoice.partner_bank_id.id
47 if not line.partner_id.bank_ids:
48 line2bank[line.id] = False
50 for bank in line.partner_id.bank_ids:
51 if bank.state in bank_type:
52 line2bank[line.id] = bank.id
54 if line.id not in line2bank and line.partner_id.bank_ids:
55 line2bank[line.id] = line.partner_id.bank_ids[0].id
57 raise osv.except_osv(_('Error!'), _('There is no partner defined on the entry line.'))
61 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: