[ADD] Module that allows for alternative partner journal accounts to be used

as defaults in imported bank statements (incl. small, necessary refactoring
in core module)
This commit is contained in:
unknown
2014-01-06 12:58:35 +01:00
committed by Holger Brunn
10 changed files with 314 additions and 39 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

@@ -875,9 +875,6 @@ class banking_import_transaction(orm.Model):
# 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
@@ -1112,24 +1109,21 @@ class banking_import_transaction(orm.Model):
account_id = move_info and move_info.get('account_id', False)
if not account_id:
# Use the default settings, but allow individual partner
# 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.
# settings to overrule this.
bank_partner = (
partner_banks[0].partner_id if len(partner_banks) == 1
else False)
if transaction.statement_line_id.amount < 0:
account_type = 'payable'
else:
account_type = 'receivable'
if len(partner_banks) == 1:
partner = partner_banks[0].partner_id
if partner.supplier and not partner.customer:
account_type = 'payable'
elif partner.customer and not partner.supplier:
account_type = 'receivable'
if partner['property_account_' + account_type]:
account_id = partner['property_account_' + account_type].id
if not account_id or account_id in (def_pay_account_id, def_rec_account_id):
if account_type == 'payable':
if bank_partner:
account_id = bank_partner.\
def_journal_account_bank_decr()[bank_partner.id]
else:
account_id = account_info.default_credit_account_id.id
else:
if bank_partner:
account_id = bank_partner.\
def_journal_account_bank_incr()[bank_partner.id]
else:
account_id = account_info.default_debit_account_id.id

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

@@ -271,27 +271,25 @@ class banking_transaction_wizard(orm.TransientModel):
else:
account_type = 'receivable'
bank_partner = False
if partner_id:
partner = wiz.statement_line_id.partner_bank_id.partner_id
if partner.supplier and not partner.customer:
account_type = 'payable'
elif partner.customer and not partner.supplier:
account_type = 'receivable'
if partner['property_account_' + account_type]:
account_id = partner['property_account_' + account_type].id
company_partner = wiz.statement_line_id.statement_id.company_id.partner_id
if len(setting_ids) and (
not account_id
or account_id in (
company_partner.property_account_payable.id,
company_partner.property_account_receivable.id)
):
setting = settings_pool.browse(cr, uid, setting_ids[0], context=context)
if account_type == 'payable':
account_id = setting.default_credit_account_id.id
else:
account_id = setting.default_debit_account_id.id
bank_partner = wiz.statement_line_id.partner_bank_id.partner_id
if wiz.amount < 0:
if bank_partner:
account_id = bank_partner.\
def_journal_account_bank_decr()[bank_partner.id]
elif setting_ids:
account_id = settings_pool.browse(
cr, uid, setting_ids[0],
context=context).default_credit_account_id.id
else:
if bank_partner:
account_id = bank_partner.\
def_journal_account_bank_incr()[bank_partner.id]
elif setting_ids:
account_id = settings_pool.browse(
cr, uid, setting_ids[0],
context=context).default_debit_account_id.id
if account_id:
wiz.statement_line_id.write({'account_id': account_id})

View File

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

View File

@@ -0,0 +1,44 @@
##############################################################################
#
# 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.
This is useful when regular transactions on clearing accounts occur. Such
clearing accounts cannot usually be selected as default partner accounts
because they are neither of type 'payable' nor 'receivable' (or at least
never at the same time!). For the alternative journal accounts for bank
transactions, any reconcilable account can be selected.
When a transaction matches a specific move in the system, the account
from the move line takes still precedence so as not to impede
reconciliation.
''',
'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,41 @@
# 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-26 19:34+0000\n"
"PO-Revision-Date: 2013-11-26 19:34+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,property_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,property_account_payable_bank_id:0
msgid "Default bank credit account"
msgstr "Standaardrekening bankafschrijvingen"
#. module: account_banking_partner_journal_account
#: help:res.partner,property_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,property_account_receivable_bank_id:0
msgid "Default bank debit account"
msgstr "Standaardrekening bankbijschrijvingen"

View File

@@ -0,0 +1,68 @@
# -*- 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 = {
'property_account_payable_bank_id': fields.property(
'account.account',
type='many2one',
relation='account.account',
string='Default bank credit account',
help=('Optional default journal account on bank statements for '
'credits from this partner. Overrides the default credit '
'account.'),
domain=[('type', '!=', 'view')]),
'property_account_receivable_bank_id': fields.property(
'account.account',
type='many2one',
relation='account.account',
string='Default bank debit account',
help=('Optional default journal account on bank statements for '
'debits from this partner. Overrides the default debit '
'account.'),
domain=[('type', '!=', 'view')]),
}
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.property_account_payable_bank_id:
res[partner.id] = partner.property_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_incr(
cr, uid, ids, context=context)
for partner in self.browse(cr, uid, ids, context=context):
if partner.property_account_receivable_bank_id:
res[partner.id] = partner.property_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="property_account_receivable_bank_id"
groups="account.group_account_invoice" />
</field>
<field name="property_account_payable" position="after">
<field name="property_account_payable_bank_id"
groups="account.group_account_invoice" />
</field>
</field>
</record>
</data>
</openerp>