1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (C) 2013 Therp BV (<http://therp.nl>).
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.
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.
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/>.
21
##############################################################################
23
from openerp.osv import orm
26
class ResPartner(orm.Model):
27
_inherit = 'res.partner'
29
def def_journal_account_bank(
30
self, cr, uid, ids, get_property_account, context=None):
32
Returns the property journal account for the given partners ids.
34
:param get_property_account: method of this object that takes
35
a partner browse record and returns a field name of type many2one.
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
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'
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'
56
def def_journal_account_bank_decr(
57
self, cr, uid, ids, context=None):
59
Return the default journal account to be used for this partner
60
in the case of bank transactions that decrease the balance.
62
return self.def_journal_account_bank(
63
cr, uid, ids, self.get_property_account_decrease, context=context)
65
def def_journal_account_bank_incr(
66
self, cr, uid, ids, context=None):
68
Return the default journal account to be used for this partner
69
in the case of bank transactions that increase the balance.
71
return self.def_journal_account_bank(
72
cr, uid, ids, self.get_property_account_increase, context=context)