[FIX] Account coda, payment, l10n_ch: minor fix
[odoo/odoo.git] / addons / l10n_ch / account_move_line.py
1 # -*- coding: utf-8 -*-
2 #
3 #  account_move_line.py
4 #  l10n_ch
5 #
6 #  Created by Nicolas Bessi based on Credric Krier contribution
7 #
8 #  Copyright (c) 2009 CamptoCamp. All rights reserved.
9 ##############################################################################
10 #
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
16 # Service Company
17 #
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.
22 #
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.
27 #
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.
31 #
32 ##############################################################################
33
34 from osv import fields, osv
35
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 """
40
41     _inherit = 'account.move.line'
42
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
50     def line2bank(self, cr, uid, ids, payment_type='manual', context=None):
51         """add a link to account.move.line in order to link
52         supplier invoice line and bank. The original link
53         was defined in account_payment"""
54         payment_mode_obj = self.pool.get('payment.mode')
55         line2bank = {}
56         if not ids:
57             return {}
58         bank_type = payment_mode_obj.suitable_bank_types(cr, uid, payment_type,
59                 context=context)
60         for line in self.browse(cr, uid, ids, context=context):
61             if line.invoice and line.invoice.partner_bank_id:
62                 line2bank[line.id] = line.invoice.partner_bank_id.id
63             elif line.partner_id:
64                 for bank in line.partner_id.bank_ids:
65                     if bank.state in bank_type:
66                         line2bank[line.id] = bank.id
67                         break
68                 if line.id not in line2bank and line.partner_id.bank_ids:
69                     line2bank[line.id] = line.partner_id.bank_ids[0].id
70         return line2bank
71
72 AccountMoveLine()
73
74 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: