Merge lp:~therp-nl/banking-addons/ba61-partner_journal_accounts into lp:banking-addons/6.1

Proposed by Stefan Rijnhart (Opener) on 2013-11-17
Status: Merged
Merged at revision: 190
Proposed branch: lp:~therp-nl/banking-addons/ba61-partner_journal_accounts
Merge into: lp:banking-addons/6.1
Diff against target: 375 lines (+294/-13)
9 files modified
account_banking/__init__.py (+1/-0)
account_banking/banking_import_transaction.py (+11/-13)
account_banking/res_partner.py (+72/-0)
account_banking_partner_journal_account/__init__.py (+1/-0)
account_banking_partner_journal_account/__openerp__.py (+44/-0)
account_banking_partner_journal_account/i18n/account_banking_partner_journal_account.pot (+35/-0)
account_banking_partner_journal_account/i18n/nl.po (+41/-0)
account_banking_partner_journal_account/res_partner.py (+68/-0)
account_banking_partner_journal_account/res_partner_view.xml (+21/-0)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/ba61-partner_journal_accounts
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review 2013-11-17 Approve on 2013-12-02
Review via email: mp+195519@code.launchpad.net

Commit message

[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)

Description of the change

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. Additional benefit is that 6.1 now also honours the customer/supplier setting on the partner in selecting the default account.

Same as 7.0 version here: https://code.launchpad.net/~therp-nl/banking-addons/ba70-partner_journal_accounts/+merge/195517 even if the changes are different against each branch. See description on the other proposal for explanation.

To post a comment you must log in.
192. By Stefan Rijnhart (Opener) on 2013-11-26

[FIX] Allow for any kind of account

193. By Stefan Rijnhart (Opener) on 2013-11-26

[RFR] Use property fields

review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_banking/__init__.py'
2--- account_banking/__init__.py 2012-01-16 16:15:55 +0000
3+++ account_banking/__init__.py 2013-11-26 19:39:26 +0000
4@@ -30,5 +30,6 @@
5 import account_banking
6 import parsers
7 import wizard
8+import res_partner
9
10 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
11
12=== modified file 'account_banking/banking_import_transaction.py'
13--- account_banking/banking_import_transaction.py 2013-09-05 21:44:46 +0000
14+++ account_banking/banking_import_transaction.py 2013-11-26 19:39:26 +0000
15@@ -1130,9 +1130,6 @@
16 # when retrieving move_line_ids below.
17 company = company_obj.browse(
18 cr, uid, transaction.company_id.id, context)
19- # Get default defaults
20- def_pay_account_id = company.partner_id.property_account_payable.id
21- def_rec_account_id = company.partner_id.property_account_receivable.id
22
23 # Get interesting journals once
24 # Added type 'general' to capture fund transfers
25@@ -1340,20 +1337,21 @@
26 # settings to overrule this. Note that you need to change
27 # the internal type of these accounts to either 'payable'
28 # or 'receivable' to enable usage like this.
29+ bank_partner = (
30+ partner_banks[0].partner_id if len(partner_banks) == 1
31+ else False)
32 if transaction.transferred_amount < 0:
33- if len(partner_banks) == 1:
34- account_id = (
35- partner_banks[0].partner_id.property_account_payable and
36- partner_banks[0].partner_id.property_account_payable.id)
37- if len(partner_banks) != 1 or not account_id or account_id == def_pay_account_id:
38+ if bank_partner:
39+ account_id = bank_partner.\
40+ def_journal_account_bank_decr()[bank_partner.id]
41+ if not account_id:
42 account_id = (account_info.default_credit_account_id and
43 account_info.default_credit_account_id.id)
44 else:
45- if len(partner_banks) == 1:
46- account_id = (
47- partner_banks[0].partner_id.property_account_receivable and
48- partner_banks[0].partner_id.property_account_receivable.id)
49- if len(partner_banks) != 1 or not account_id or account_id == def_rec_account_id:
50+ if bank_partner:
51+ account_id = bank_partner.\
52+ def_journal_account_bank_incr()[bank_partner.id]
53+ if not account_id:
54 account_id = (account_info.default_debit_account_id and
55 account_info.default_debit_account_id.id)
56 values = {}
57
58=== added file 'account_banking/res_partner.py'
59--- account_banking/res_partner.py 1970-01-01 00:00:00 +0000
60+++ account_banking/res_partner.py 2013-11-26 19:39:26 +0000
61@@ -0,0 +1,72 @@
62+# -*- encoding: utf-8 -*-
63+##############################################################################
64+#
65+# Copyright (C) 2013 Therp BV (<http://therp.nl>).
66+#
67+# All Rights Reserved
68+#
69+# This program is free software: you can redistribute it and/or modify
70+# it under the terms of the GNU General Public License as published by
71+# the Free Software Foundation, either version 3 of the License, or
72+# (at your option) any later version.
73+#
74+# This program is distributed in the hope that it will be useful,
75+# but WITHOUT ANY WARRANTY; without even the implied warranty of
76+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77+# GNU General Public License for more details.
78+#
79+# You should have received a copy of the GNU General Public License
80+# along with this program. If not, see <http://www.gnu.org/licenses/>.
81+#
82+##############################################################################
83+
84+from openerp.osv import orm
85+
86+
87+class ResPartner(orm.Model):
88+ _inherit = 'res.partner'
89+
90+ def def_journal_account_bank(
91+ self, cr, uid, ids, get_property_account, context=None):
92+ """
93+ Returns the property journal account for the given partners ids.
94+
95+ :param get_property_account: method of this object that takes
96+ a partner browse record and returns a field name of type many2one.
97+ """
98+ if not ids:
99+ return {}
100+ res = dict([(res_id, False) for res_id in ids])
101+ for partner in self.browse(cr, uid, ids, context=context):
102+ property_account = get_property_account(partner)
103+ if partner[property_account]:
104+ res[partner.id] = partner[property_account].id
105+ return res
106+
107+ def get_property_account_decrease(self, partner):
108+ if partner.customer and not partner.supplier:
109+ return 'property_account_receivable'
110+ return 'property_account_payable'
111+
112+ def get_property_account_increase(self, partner):
113+ if partner.supplier and not partner.customer:
114+ return 'property_account_payable'
115+ return 'property_account_receivable'
116+
117+ def def_journal_account_bank_decr(
118+ self, cr, uid, ids, context=None):
119+ """
120+ Return the default journal account to be used for this partner
121+ in the case of bank transactions that decrease the balance.
122+ """
123+ return self.def_journal_account_bank(
124+ cr, uid, ids, self.get_property_account_decrease, context=context)
125+
126+ def def_journal_account_bank_incr(
127+ self, cr, uid, ids, context=None):
128+ """
129+ Return the default journal account to be used for this partner
130+ in the case of bank transactions that increase the balance.
131+ """
132+ return self.def_journal_account_bank(
133+ cr, uid, ids, self.get_property_account_increase, context=context)
134
135=== added directory 'account_banking_partner_journal_account'
136=== added file 'account_banking_partner_journal_account/__init__.py'
137--- account_banking_partner_journal_account/__init__.py 1970-01-01 00:00:00 +0000
138+++ account_banking_partner_journal_account/__init__.py 2013-11-26 19:39:26 +0000
139@@ -0,0 +1,1 @@
140+from . import res_partner
141
142=== added file 'account_banking_partner_journal_account/__openerp__.py'
143--- account_banking_partner_journal_account/__openerp__.py 1970-01-01 00:00:00 +0000
144+++ account_banking_partner_journal_account/__openerp__.py 2013-11-26 19:39:26 +0000
145@@ -0,0 +1,44 @@
146+##############################################################################
147+#
148+# Copyright (C) 2013 Therp BV (<http://therp.nl>)
149+# All Rights Reserved
150+#
151+# This program is free software: you can redistribute it and/or modify
152+# it under the terms of the GNU Affero General Public License as published by
153+# the Free Software Foundation, either version 3 of the License, or
154+# (at your option) any later version.
155+#
156+# This program is distributed in the hope that it will be useful,
157+# but WITHOUT ANY WARRANTY; without even the implied warranty of
158+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
159+# GNU Affero General Public License for more details.
160+#
161+# You should have received a copy of the GNU Affero General Public License
162+# along with this program. If not, see <http://www.gnu.org/licenses/>.
163+#
164+##############################################################################
165+{
166+ 'name': 'Banking Addons - Default partner journal accounts for bank transactions',
167+ 'version': '0.1',
168+ 'license': 'AGPL-3',
169+ 'author': 'Therp BV',
170+ 'website': 'https://launchpad.net/banking-addons',
171+ 'category': 'Banking addons',
172+ 'depends': ['account_banking'],
173+ 'description': '''
174+This module allows to set alternative journal accounts on partners to use
175+as default accounts in imported bank statements.
176+
177+This is useful when regular transactions on clearing accounts occur. Such
178+clearing accounts cannot usually be selected as default partner accounts
179+because they are neither of type 'payable' nor 'receivable' (or at least
180+never at the same time!). For the alternative journal accounts for bank
181+transactions, any reconcilable account can be selected.
182+
183+When a transaction matches a specific move in the system, the account
184+from the move line takes still precedence so as not to impede
185+reconciliation.
186+ ''',
187+ 'data': ['res_partner_view.xml'],
188+ 'installable': True,
189+}
190
191=== added directory 'account_banking_partner_journal_account/i18n'
192=== added file 'account_banking_partner_journal_account/i18n/account_banking_partner_journal_account.pot'
193--- account_banking_partner_journal_account/i18n/account_banking_partner_journal_account.pot 1970-01-01 00:00:00 +0000
194+++ account_banking_partner_journal_account/i18n/account_banking_partner_journal_account.pot 2013-11-26 19:39:26 +0000
195@@ -0,0 +1,35 @@
196+# Translation of OpenERP Server.
197+# This file contains the translation of the following modules:
198+# * account_banking_partner_journal_account
199+#
200+msgid ""
201+msgstr ""
202+
203+#. module: account_banking_partner_journal_account
204+#: model:ir.model,name:account_banking_partner_journal_account.model_res_partner
205+msgid "Partner"
206+msgstr ""
207+
208+#. module: account_banking_partner_journal_account
209+#: help:res.partner,account_receivable_bank_id:0
210+msgid ""
211+"Optional default journal account on bank statements for debits from this "
212+"partner. Overrides the default debit account."
213+msgstr ""
214+
215+#. module: account_banking_partner_journal_account
216+#: field:res.partner,account_payable_bank_id:0
217+msgid "Default bank credit account"
218+msgstr ""
219+
220+#. module: account_banking_partner_journal_account
221+#: help:res.partner,account_payable_bank_id:0
222+msgid ""
223+"Optional default journal account on bank statements for credits from this "
224+"partner. Overrides the default credit account."
225+msgstr ""
226+
227+#. module: account_banking_partner_journal_account
228+#: field:res.partner,account_receivable_bank_id:0
229+msgid "Default bank debit account"
230+msgstr ""
231
232=== added file 'account_banking_partner_journal_account/i18n/nl.po'
233--- account_banking_partner_journal_account/i18n/nl.po 1970-01-01 00:00:00 +0000
234+++ account_banking_partner_journal_account/i18n/nl.po 2013-11-26 19:39:26 +0000
235@@ -0,0 +1,41 @@
236+# Translation of OpenERP Server.
237+# This file contains the translation of the following modules:
238+# * account_banking_partner_journal_account
239+#
240+msgid ""
241+msgstr ""
242+"Project-Id-Version: OpenERP Server 6.1\n"
243+"Report-Msgid-Bugs-To: \n"
244+"POT-Creation-Date: 2013-11-26 19:34+0000\n"
245+"PO-Revision-Date: 2013-11-26 19:34+0000\n"
246+"Last-Translator: <>\n"
247+"Language-Team: \n"
248+"MIME-Version: 1.0\n"
249+"Content-Type: text/plain; charset=UTF-8\n"
250+"Content-Transfer-Encoding: \n"
251+"Plural-Forms: \n"
252+
253+#. module: account_banking_partner_journal_account
254+#: model:ir.model,name:account_banking_partner_journal_account.model_res_partner
255+msgid "Partner"
256+msgstr "Relatie"
257+
258+#. module: account_banking_partner_journal_account
259+#: help:res.partner,property_account_receivable_bank_id:0
260+msgid "Optional default journal account on bank statements for debits from this partner. Overrides the default debit account."
261+msgstr "Optionele standaard grootboekrekening voor geïmporteerde bankbijschrijvingen, in plaats van de standaard debiteurenrekening."
262+
263+#. module: account_banking_partner_journal_account
264+#: field:res.partner,property_account_payable_bank_id:0
265+msgid "Default bank credit account"
266+msgstr "Standaardrekening bankafschrijvingen"
267+
268+#. module: account_banking_partner_journal_account
269+#: help:res.partner,property_account_payable_bank_id:0
270+msgid "Optional default journal account on bank statements for credits from this partner. Overrides the default credit account."
271+msgstr "Optionele standaard grootboekrekening voor geïmporteerde bankafschrijvingen, in plaats van de standaard crediteurenrekening."
272+
273+#. module: account_banking_partner_journal_account
274+#: field:res.partner,property_account_receivable_bank_id:0
275+msgid "Default bank debit account"
276+msgstr "Standaardrekening bankbijschrijvingen"
277
278=== added file 'account_banking_partner_journal_account/res_partner.py'
279--- account_banking_partner_journal_account/res_partner.py 1970-01-01 00:00:00 +0000
280+++ account_banking_partner_journal_account/res_partner.py 2013-11-26 19:39:26 +0000
281@@ -0,0 +1,68 @@
282+# -*- coding: utf-8 -*-
283+##############################################################################
284+#
285+# Copyright (C) 2013 Therp BV (<http://therp.nl>).
286+#
287+# This program is free software: you can redistribute it and/or modify
288+# it under the terms of the GNU Affero General Public License as
289+# published by the Free Software Foundation, either version 3 of the
290+# License, or (at your option) any later version.
291+#
292+# This program is distributed in the hope that it will be useful,
293+# but WITHOUT ANY WARRANTY; without even the implied warranty of
294+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
295+# GNU Affero General Public License for more details.
296+#
297+# You should have received a copy of the GNU Affero General Public License
298+# along with this program. If not, see <http://www.gnu.org/licenses/>.
299+#
300+##############################################################################
301+
302+from openerp.osv import orm, fields
303+
304+
305+class ResPartner(orm.Model):
306+ _inherit = 'res.partner'
307+
308+ _columns = {
309+ 'property_account_payable_bank_id': fields.property(
310+ 'account.account',
311+ type='many2one',
312+ relation='account.account',
313+ string='Default bank credit account',
314+ help=('Optional default journal account on bank statements for '
315+ 'credits from this partner. Overrides the default credit '
316+ 'account.'),
317+ domain=[('type', '!=', 'view')]),
318+ 'property_account_receivable_bank_id': fields.property(
319+ 'account.account',
320+ type='many2one',
321+ relation='account.account',
322+ string='Default bank debit account',
323+ help=('Optional default journal account on bank statements for '
324+ 'debits from this partner. Overrides the default debit '
325+ 'account.'),
326+ domain=[('type', '!=', 'view')]),
327+ }
328+
329+ def def_journal_account_bank_decr(
330+ self, cr, uid, ids, context=None):
331+ if not ids:
332+ return {}
333+ res = super(ResPartner, self).def_journal_account_bank_decr(
334+ cr, uid, ids, context=context)
335+ for partner in self.browse(cr, uid, ids, context=context):
336+ if partner.property_account_payable_bank_id:
337+ res[partner.id] = partner.property_account_payable_bank_id.id
338+ return res
339+
340+ def def_journal_account_bank_incr(
341+ self, cr, uid, ids, context=None):
342+ if not ids:
343+ return {}
344+ res = super(ResPartner, self).def_journal_account_bank_incr(
345+ cr, uid, ids, context=context)
346+ for partner in self.browse(cr, uid, ids, context=context):
347+ if partner.property_account_receivable_bank_id:
348+ res[partner.id] = partner.property_account_receivable_bank_id.id
349+ return res
350
351=== added file 'account_banking_partner_journal_account/res_partner_view.xml'
352--- account_banking_partner_journal_account/res_partner_view.xml 1970-01-01 00:00:00 +0000
353+++ account_banking_partner_journal_account/res_partner_view.xml 2013-11-26 19:39:26 +0000
354@@ -0,0 +1,21 @@
355+<?xml version="1.0" encoding="utf-8"?>
356+<openerp>
357+ <data>
358+ <record id="view_partner_form" model="ir.ui.view">
359+ <field name="name">Add default accounts on bank statements</field>
360+ <field name="model">res.partner</field>
361+ <field name="inherit_id" ref="base.view_partner_form"/>
362+ <field name="arch" type="xml">
363+ <field name="property_account_receivable" position="after">
364+ <field name="property_account_receivable_bank_id"
365+ groups="account.group_account_invoice" />
366+ </field>
367+ <field name="property_account_payable" position="after">
368+ <field name="property_account_payable_bank_id"
369+ groups="account.group_account_invoice" />
370+ </field>
371+ </field>
372+ </record>
373+ </data>
374+</openerp>
375+

Subscribers

People subscribed via source and target branches