~therp-nl/banking-addons/ba61-custom_debit_order_reference_cust73

« back to all changes in this revision

Viewing changes to account_banking/res_partner.py

  • Committer: Stefan Rijnhart
  • Date: 2014-01-11 16:12:22 UTC
  • mfrom: (155.22.13 banking-addons-6.1)
  • Revision ID: stefan@therp.nl-20140111161222-oyg1wpjaifsslex9
[MRG] lp:banking-addons/6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Copyright (C) 2013 Therp BV (<http://therp.nl>).
 
5
#
 
6
#    All Rights Reserved
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from openerp.osv import orm
 
24
 
 
25
 
 
26
class ResPartner(orm.Model):
 
27
    _inherit = 'res.partner'
 
28
 
 
29
    def def_journal_account_bank(
 
30
            self, cr, uid, ids, get_property_account, context=None):
 
31
        """
 
32
        Returns the property journal account for the given partners ids.
 
33
        
 
34
        :param get_property_account: method of this object that takes
 
35
        a partner browse record and returns a field name of type many2one.
 
36
        """
 
37
        if not ids:
 
38
            return {}
 
39
        res = dict([(res_id, False) for res_id in ids])
 
40
        for partner in self.browse(cr, uid, ids, context=context):
 
41
            property_account = get_property_account(partner)
 
42
            if partner[property_account]:
 
43
                res[partner.id] = partner[property_account].id
 
44
        return res
 
45
 
 
46
    def get_property_account_decrease(self, partner):
 
47
        if partner.customer and not partner.supplier:
 
48
            return 'property_account_receivable'
 
49
        return 'property_account_payable'
 
50
 
 
51
    def get_property_account_increase(self, partner):
 
52
        if partner.supplier and not partner.customer:
 
53
            return 'property_account_payable'
 
54
        return 'property_account_receivable'
 
55
 
 
56
    def def_journal_account_bank_decr(
 
57
            self, cr, uid, ids, context=None):
 
58
        """
 
59
        Return the default journal account to be used for this partner
 
60
        in the case of bank transactions that decrease the balance.
 
61
        """
 
62
        return self.def_journal_account_bank(
 
63
            cr, uid, ids, self.get_property_account_decrease, context=context)
 
64
 
 
65
    def def_journal_account_bank_incr(
 
66
            self, cr, uid, ids, context=None):
 
67
        """
 
68
        Return the default journal account to be used for this partner
 
69
        in the case of bank transactions that increase the balance.
 
70
        """
 
71
        return self.def_journal_account_bank(
 
72
            cr, uid, ids, self.get_property_account_increase, context=context)