Launchpad automatic translations update.
[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     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')
54         line2bank = {}
55         if not ids:
56             return {}
57         bank_type = payment_mode_obj.suitable_bank_types(cr, uid, payment_type,
58                 context=context)
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
62             elif line.partner_id:
63                 for bank in line.partner_id.bank_ids:
64                     if bank.state in bank_type:
65                         line2bank[line.id] = bank.id
66                         break
67                 if line.id not in line2bank and line.partner_id.bank_ids:
68                     line2bank[line.id] = line.partner_id.bank_ids[0].id
69         return line2bank
70
71 AccountMoveLine()
72 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: