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