1 # -*- coding: utf-8 -*-
6 # Created by Nicolas Bessi based on Credric Krier contribution
8 # Copyright (c) 2009 CamptoCamp. All rights reserved.
9 ##############################################################################
11 # WARNING: This program as such is intended to be used by professional
12 # programmers who take the whole responsability of assessing all potential
13 # consequences resulting from its eventual inadequacies and bugs
14 # End users who are looking for a ready-to-use solution with commercial
15 # garantees and support are strongly adviced to contract a Free Software
18 # This program is Free Software; you can redistribute it and/or
19 # modify it under the terms of the GNU General Public License
20 # as published by the Free Software Foundation; either version 2
21 # of the License, or (at your option) any later version.
23 # This program is distributed in the hope that it will be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 # GNU General Public License for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write to the Free Software
30 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 ##############################################################################
34 from osv import fields, osv
36 class AccountMoveLine(osv.osv):
37 """ Inherit account.move.line in order to add a custom link
38 between supplier invoice line and bank. The original link
39 was defined in account_payment between line """
41 _inherit = 'account.move.line'
43 ## @param self The object pointer.
44 ## @param cr a psycopg cursor
45 ## @param uid res.user.id that is currently loged
46 ## @param payment_type manual
47 ## @parma context a standard dict
48 ## @return a dict who has the account move line id as key and the bank id as value
49 def line2bank(self, cr, uid, ids, payment_type='manual', context=None):
50 """add a link to account.move.line in order to link
51 supplier invoice line and bank. The original link
52 was defined in account_payment"""
53 payment_mode_obj = self.pool.get('payment.mode')
57 bank_type = payment_mode_obj.suitable_bank_types(cr, uid, payment_type,
59 for line in self.browse(cr, uid, ids, context=context):
60 if line.invoice and line.invoice.partner_bank_id:
61 line2bank[line.id] = line.invoice.partner_bank_id.id
63 for bank in line.partner_id.bank_ids:
64 if bank.state in bank_type:
65 line2bank[line.id] = bank.id
67 if line.id not in line2bank and line.partner_id.bank_ids:
68 line2bank[line.id] = line.partner_id.bank_ids[0].id
72 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: