[RFR] Refactor out the code that retrieves default debit or credit

account of the partner
[RFR] Remove suspicious references to the company partner
	debit and credit accounts
[ADD] Module that allows for alternative partner journal accounts
	to be used as defaults in imported bank statements
This commit is contained in:
Stefan Rijnhart
2013-11-16 11:37:09 +01:00
parent b97c396c9f
commit 20c3fa915f
9 changed files with 281 additions and 13 deletions

View File

@@ -30,5 +30,6 @@ import banking_import_transaction
import account_banking
import parsers
import wizard
import res_partner
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -1130,9 +1130,6 @@ class banking_import_transaction(osv.osv):
# when retrieving move_line_ids below.
company = company_obj.browse(
cr, uid, transaction.company_id.id, context)
# Get default defaults
def_pay_account_id = company.partner_id.property_account_payable.id
def_rec_account_id = company.partner_id.property_account_receivable.id
# Get interesting journals once
# Added type 'general' to capture fund transfers
@@ -1340,20 +1337,21 @@ class banking_import_transaction(osv.osv):
# settings to overrule this. Note that you need to change
# the internal type of these accounts to either 'payable'
# or 'receivable' to enable usage like this.
bank_partner = (
partner_banks[0].partner_id if len(partner_banks) == 1
else False)
if transaction.transferred_amount < 0:
if len(partner_banks) == 1:
account_id = (
partner_banks[0].partner_id.property_account_payable and
partner_banks[0].partner_id.property_account_payable.id)
if len(partner_banks) != 1 or not account_id or account_id == def_pay_account_id:
if bank_partner:
account_id = bank_partner.\
def_journal_account_bank_decr()[bank_partner.id]
if not account_id:
account_id = (account_info.default_credit_account_id and
account_info.default_credit_account_id.id)
else:
if len(partner_banks) == 1:
account_id = (
partner_banks[0].partner_id.property_account_receivable and
partner_banks[0].partner_id.property_account_receivable.id)
if len(partner_banks) != 1 or not account_id or account_id == def_rec_account_id:
if bank_partner:
account_id = bank_partner.\
def_journal_account_bank_incr()[bank_partner.id]
if not account_id:
account_id = (account_info.default_debit_account_id and
account_info.default_debit_account_id.id)
values = {}

View File

@@ -0,0 +1,72 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Therp BV (<http://therp.nl>).
#
# All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
class ResPartner(orm.Model):
_inherit = 'res.partner'
def def_journal_account_bank(
self, cr, uid, ids, get_property_account, context=None):
"""
Returns the property journal account for the given partners ids.
:param get_property_account: method of this object that takes
a partner browse record and returns a field name of type many2one.
"""
if not ids:
return {}
res = dict([(res_id, False) for res_id in ids])
for partner in self.browse(cr, uid, ids, context=context):
property_account = get_property_account(partner)
if partner[property_account]:
res[partner.id] = partner[property_account].id
return res
def get_property_account_decrease(self, partner):
if partner.customer and not partner.supplier:
return 'property_account_receivable'
return 'property_account_payable'
def get_property_account_increase(self, partner):
if partner.supplier and not partner.customer:
return 'property_account_payable'
return 'property_account_receivable'
def def_journal_account_bank_decr(
self, cr, uid, ids, context=None):
"""
Return the default journal account to be used for this partner
in the case of bank transactions that decrease the balance.
"""
return self.def_journal_account_bank(
cr, uid, ids, self.get_property_account_decrease, context=context)
def def_journal_account_bank_incr(
self, cr, uid, ids, context=None):
"""
Return the default journal account to be used for this partner
in the case of bank transactions that increase the balance.
"""
return self.def_journal_account_bank(
cr, uid, ids, self.get_property_account_increase, context=context)

View File

@@ -0,0 +1 @@
from . import res_partner

View File

@@ -0,0 +1,34 @@
##############################################################################
#
# Copyright (C) 2013 Therp BV (<http://therp.nl>)
# All Rights Reserved
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Banking Addons - Default partner journal accounts for bank transactions',
'version': '0.1',
'license': 'AGPL-3',
'author': 'Therp BV',
'website': 'https://launchpad.net/banking-addons',
'category': 'Banking addons',
'depends': ['account_banking'],
'description': '''
This module allows to set alternative journal accounts on partners to use
as default accounts in imported bank statements.
''',
'data': ['res_partner_view.xml'],
'installable': True,
}

View File

@@ -0,0 +1,35 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_banking_partner_journal_account
#
msgid ""
msgstr ""
#. module: account_banking_partner_journal_account
#: model:ir.model,name:account_banking_partner_journal_account.model_res_partner
msgid "Partner"
msgstr ""
#. module: account_banking_partner_journal_account
#: help:res.partner,account_receivable_bank_id:0
msgid ""
"Optional default journal account on bank statements for debits from this "
"partner. Overrides the default debit account."
msgstr ""
#. module: account_banking_partner_journal_account
#: field:res.partner,account_payable_bank_id:0
msgid "Default bank credit account"
msgstr ""
#. module: account_banking_partner_journal_account
#: help:res.partner,account_payable_bank_id:0
msgid ""
"Optional default journal account on bank statements for credits from this "
"partner. Overrides the default credit account."
msgstr ""
#. module: account_banking_partner_journal_account
#: field:res.partner,account_receivable_bank_id:0
msgid "Default bank debit account"
msgstr ""

View File

@@ -0,0 +1,42 @@
# Translation of OpenERP Server.
# This file contains the translation of the following modules:
# * account_banking_partner_journal_account
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 6.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-16 10:29+0000\n"
"PO-Revision-Date: 2013-11-16 10:29+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: account_banking_partner_journal_account
#: model:ir.model,name:account_banking_partner_journal_account.model_res_partner
msgid "Partner"
msgstr "Relatie"
#. module: account_banking_partner_journal_account
#: help:res.partner,account_receivable_bank_id:0
msgid "Optional default journal account on bank statements for debits from this partner. Overrides the default debit account."
msgstr "Optionele standaard grootboekrekening voor geïmporteerde bankbijschrijvingen, in plaats van de standaard debiteurenrekening."
#. module: account_banking_partner_journal_account
#: field:res.partner,account_payable_bank_id:0
msgid "Default bank credit account"
msgstr "Standaardrekening afschrijvingen"
#. module: account_banking_partner_journal_account
#: help:res.partner,account_payable_bank_id:0
msgid "Optional default journal account on bank statements for credits from this partner. Overrides the default credit account."
msgstr "Optionele standaard grootboekrekening voor geïmporteerde bankafschrijvingen, in plaats van de standaard crediteurenrekening."
#. module: account_banking_partner_journal_account
#: field:res.partner,account_receivable_bank_id:0
msgid "Default bank debit account"
msgstr "Standaardrekening bankbijschrijvingen"

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Therp BV (<http://therp.nl>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm, fields
class ResPartner(orm.Model):
_inherit = 'res.partner'
_columns = {
'account_payable_bank_id': fields.many2one(
'account.account',
'Default bank credit account',
help=('Optional default journal account on bank statements for '
'credits from this partner. Overrides the default credit '
'account.'),
domain=[('reconcile', '=', True)]),
'account_receivable_bank_id': fields.many2one(
'account.account',
'Default bank debit account',
help=('Optional default journal account on bank statements for '
'debits from this partner. Overrides the default debit '
'account.'),
domain=[('reconcile', '=', True)]),
}
def def_journal_account_bank_decr(
self, cr, uid, ids, context=None):
if not ids:
return {}
res = super(ResPartner, self).def_journal_account_bank_decr(
cr, uid, ids, context=context)
for partner in self.browse(cr, uid, ids, context=context):
if partner.account_payable_bank_id:
res[partner.id] = partner.account_payable_bank_id.id
return res
def def_journal_account_bank_incr(
self, cr, uid, ids, context=None):
if not ids:
return {}
res = super(ResPartner, self).def_journal_account_bank_decr(
cr, uid, ids, context=context)
for partner in self.browse(cr, uid, ids, context=context):
if partner.account_receivable_bank_id:
res[partner.id] = partner.account_receivable_bank_id.id
return res

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">Add default accounts on bank statements</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="property_account_receivable" position="after">
<field name="account_receivable_bank_id"
groups="account.group_account_invoice" />
</field>
<field name="property_account_payable" position="after">
<field name="account_payable_bank_id"
groups="account.group_account_invoice" />
</field>
</field>
</record>
</data>
</openerp>