← Back to team overview

banking-addons-team team mailing list archive

[Merge] lp:~therp-nl/banking-addons/ba70-partner_journal_accounts into lp:banking-addons

 

Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/banking-addons/ba70-partner_journal_accounts into lp:banking-addons.

Requested reviews:
  Banking Addons Core Editors (banking-addons-team)

For more details, see:
https://code.launchpad.net/~therp-nl/banking-addons/ba70-partner_journal_accounts/+merge/195517

Adding a module with the following 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.
===

About the code:

For this functionality, a small refactoring was needed in account_banking

Same as 6.1 version here: https://code.launchpad.net/~therp-nl/banking-addons/ba61-partner_journal_accounts/+merge/195519, except that in 7.0 the code to retrieve the default account was already honouring the customer/supplier setting of the partner. These lines are now refactored.

There is also an additional change in 7.0 because this version resets the account when matching is being undone which calls for the same logic.
-- 
https://code.launchpad.net/~therp-nl/banking-addons/ba70-partner_journal_accounts/+merge/195517
Your team Banking Addons Core Editors is requested to review the proposed merge of lp:~therp-nl/banking-addons/ba70-partner_journal_accounts into lp:banking-addons.
=== modified file 'account_banking/__init__.py'
--- account_banking/__init__.py	2013-04-15 13:59:50 +0000
+++ account_banking/__init__.py	2013-11-17 20:04:28 +0000
@@ -30,5 +30,6 @@
 import account_banking
 import parsers
 import wizard
+import res_partner
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'account_banking/banking_import_transaction.py'
--- account_banking/banking_import_transaction.py	2013-10-14 12:33:57 +0000
+++ account_banking/banking_import_transaction.py	2013-11-17 20:04:28 +0000
@@ -875,9 +875,6 @@
             # 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 @@
             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
 

=== added file 'account_banking/res_partner.py'
--- account_banking/res_partner.py	1970-01-01 00:00:00 +0000
+++ account_banking/res_partner.py	2013-11-17 20:04:28 +0000
@@ -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)

=== modified file 'account_banking/wizard/banking_transaction_wizard.py'
--- account_banking/wizard/banking_transaction_wizard.py	2013-10-14 12:33:57 +0000
+++ account_banking/wizard/banking_transaction_wizard.py	2013-11-17 20:04:28 +0000
@@ -271,27 +271,25 @@
             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})

=== added directory 'account_banking_partner_journal_account'
=== added file 'account_banking_partner_journal_account/__init__.py'
--- account_banking_partner_journal_account/__init__.py	1970-01-01 00:00:00 +0000
+++ account_banking_partner_journal_account/__init__.py	2013-11-17 20:04:28 +0000
@@ -0,0 +1,1 @@
+from . import res_partner

=== added file 'account_banking_partner_journal_account/__openerp__.py'
--- account_banking_partner_journal_account/__openerp__.py	1970-01-01 00:00:00 +0000
+++ account_banking_partner_journal_account/__openerp__.py	2013-11-17 20:04:28 +0000
@@ -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,
+}

=== added directory 'account_banking_partner_journal_account/i18n'
=== added file 'account_banking_partner_journal_account/i18n/account_banking_partner_journal_account.pot'
--- account_banking_partner_journal_account/i18n/account_banking_partner_journal_account.pot	1970-01-01 00:00:00 +0000
+++ account_banking_partner_journal_account/i18n/account_banking_partner_journal_account.pot	2013-11-17 20:04:28 +0000
@@ -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 ""

=== added file 'account_banking_partner_journal_account/i18n/nl.po'
--- account_banking_partner_journal_account/i18n/nl.po	1970-01-01 00:00:00 +0000
+++ account_banking_partner_journal_account/i18n/nl.po	2013-11-17 20:04:28 +0000
@@ -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 bankafschrijvingen"
+
+#. 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"
+

=== added file 'account_banking_partner_journal_account/res_partner.py'
--- account_banking_partner_journal_account/res_partner.py	1970-01-01 00:00:00 +0000
+++ account_banking_partner_journal_account/res_partner.py	2013-11-17 20:04:28 +0000
@@ -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_incr(
+            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

=== added file 'account_banking_partner_journal_account/res_partner_view.xml'
--- account_banking_partner_journal_account/res_partner_view.xml	1970-01-01 00:00:00 +0000
+++ account_banking_partner_journal_account/res_partner_view.xml	2013-11-17 20:04:28 +0000
@@ -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>
+


Follow ups