Merge lp:~therp-nl/banking-addons/ba70-select_account_by_customer_supplier_setting into lp:banking-addons

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 193
Proposed branch: lp:~therp-nl/banking-addons/ba70-select_account_by_customer_supplier_setting
Merge into: lp:banking-addons
Diff against target: 109 lines (+50/-23)
2 files modified
account_banking/banking_import_transaction.py (+17/-15)
account_banking/wizard/banking_transaction_wizard.py (+33/-8)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/ba70-select_account_by_customer_supplier_setting
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Pedro Manuel Baeza code review, no test Approve
Review via email: mp+181818@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

It's a bit complicated to follow all the variables involved (partner_banks, settings, account_info, etc), but there are checks to avoid errors and I trust you know what you're doing ;)

review: Approve (code review, no test)
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Yes, I agree. When I did this change I was considering doing away with the default account settings entirely and rely on the company property settings instead (and not the company *partner* settings, which I believe is a legacy thing here). But I think I should ask around first if anyone is using this override, and make it a separate change later on.

Revision history for this message
Holger Brunn (Therp) (hbrunn) :
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/banking_import_transaction.py'
2--- account_banking/banking_import_transaction.py 2013-08-12 09:20:35 +0000
3+++ account_banking/banking_import_transaction.py 2013-08-23 12:51:00 +0000
4@@ -1112,21 +1112,23 @@
5 # the internal type of these accounts to either 'payable'
6 # or 'receivable' to enable usage like this.
7 if transaction.statement_line_id.amount < 0:
8- if len(partner_banks) == 1:
9- account_id = (
10- partner_banks[0].partner_id.property_account_payable and
11- partner_banks[0].partner_id.property_account_payable.id)
12- if len(partner_banks) != 1 or not account_id or account_id == def_pay_account_id:
13- account_id = (account_info.default_credit_account_id and
14- account_info.default_credit_account_id.id)
15+ account_type = 'payable'
16 else:
17- if len(partner_banks) == 1:
18- account_id = (
19- partner_banks[0].partner_id.property_account_receivable and
20- partner_banks[0].partner_id.property_account_receivable.id)
21- if len(partner_banks) != 1 or not account_id or account_id == def_rec_account_id:
22- account_id = (account_info.default_debit_account_id and
23- account_info.default_debit_account_id.id)
24+ account_type = 'receivable'
25+ if len(partner_banks) == 1:
26+ partner = partner_banks[0].partner_id
27+ if partner.supplier and not partner.customer:
28+ account_type = 'payable'
29+ elif partner.customer and not partner.supplier:
30+ account_type = 'receivable'
31+ if partner['property_account_' + account_type]:
32+ account_id = partner['property_account_' + account_type].id
33+ if not account_id or account_id in (def_pay_account_id, def_rec_account_id):
34+ if account_type == 'payable':
35+ account_id = account_info.default_credit_account_id.id
36+ else:
37+ account_id = account_info.default_debit_account_id.id
38+
39 values = {'account_id': account_id}
40 self_values = {}
41 if move_info:
42@@ -1495,7 +1497,7 @@
43
44 if (not statement_line.import_transaction_id or
45 not statement_line.import_transaction_id.remote_account):
46- raise osv.except_osv(
47+ raise orm.except_orm(
48 _("Error"),
49 _("No bank account available to link partner to"))
50
51
52=== modified file 'account_banking/wizard/banking_transaction_wizard.py'
53--- account_banking/wizard/banking_transaction_wizard.py 2013-08-12 09:20:35 +0000
54+++ account_banking/wizard/banking_transaction_wizard.py 2013-08-23 12:51:00 +0000
55@@ -256,14 +256,7 @@
56 account_id = False
57 journal_id = wiz.statement_line_id.statement_id.journal_id.id
58 setting_ids = settings_pool.find(cr, uid, journal_id, context=context)
59- if len(setting_ids)>0:
60- setting = settings_pool.browse(cr, uid, setting_ids[0], context=context)
61- if wiz.amount < 0:
62- account_id = setting.default_credit_account_id and setting.default_credit_account_id.id
63- else:
64- account_id = setting.default_debit_account_id and setting.default_debit_account_id.id
65- statement_pool.write(cr, uid, wiz.statement_line_id.id, {'account_id':account_id})
66-
67+
68 # Restore partner id from the bank account or else reset
69 partner_id = False
70 if (wiz.statement_line_id.partner_bank_id and
71@@ -271,6 +264,38 @@
72 partner_id = wiz.statement_line_id.partner_bank_id.partner_id.id
73 wiz.write({'partner_id': partner_id})
74
75+ # Select account type by parter customer or supplier,
76+ # or default based on amount sign
77+ if wiz.amount < 0:
78+ account_type = 'payable'
79+ else:
80+ account_type = 'receivable'
81+
82+ if partner_id:
83+ partner = wiz.statement_line_id.partner_bank_id.partner_id
84+ if partner.supplier and not partner.customer:
85+ account_type = 'payable'
86+ elif partner.customer and not partner.supplier:
87+ account_type = 'receivable'
88+ if partner['property_account_' + account_type]:
89+ account_id = partner['property_account_' + account_type].id
90+
91+ company_partner = wiz.statement_line_id.statement_id.company_id.partner_id
92+ if len(setting_ids) and (
93+ not account_id
94+ or account_id in (
95+ company_partner.property_account_payable.id,
96+ company_partner.property_account_receivable.id)
97+ ):
98+ setting = settings_pool.browse(cr, uid, setting_ids[0], context=context)
99+ if account_type == 'payable':
100+ account_id = setting.default_credit_account_id.id
101+ else:
102+ account_id = setting.default_debit_account_id.id
103+
104+ if account_id:
105+ wiz.statement_line_id.write({'account_id': account_id})
106+
107 if wiz.statement_line_id:
108 #delete splits causing an unsplit if this is a split
109 #transaction

Subscribers

People subscribed via source and target branches

to status/vote changes: