Merge lp:~qdp/openobject-addons/5.0-fix-bank-statement-onchange into lp:openobject-addons/5.0

Proposed by qdp (OpenERP)
Status: Merged
Merged at revision: not available
Proposed branch: lp:~qdp/openobject-addons/5.0-fix-bank-statement-onchange
Merge into: lp:openobject-addons/5.0
Diff against target: 65 lines (+26/-21)
1 file modified
account/account_bank_statement.py (+26/-21)
To merge this branch: bzr merge lp:~qdp/openobject-addons/5.0-fix-bank-statement-onchange
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+22854@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account_bank_statement.py'
2--- account/account_bank_statement.py 2010-02-04 11:47:04 +0000
3+++ account/account_bank_statement.py 2010-04-06 09:50:30 +0000
4@@ -529,35 +529,40 @@
5
6 def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id,
7 context={}):
8+ res = {'value': {}}
9 if not partner_id:
10- return {}
11- res_currency_obj = self.pool.get('res.currency')
12- res_users_obj = self.pool.get('res.users')
13-
14- company_currency_id = res_users_obj.browse(cursor, user, user,
15- context=context).company_id.currency_id.id
16-
17- if not currency_id:
18- currency_id = company_currency_id
19-
20- part = self.pool.get('res.partner').browse(cursor, user, partner_id,
21+ return res
22+ line = self.browse(cursor, user, line_id)
23+
24+ if not line or (line and not line[0].account_id):
25+ part = self.pool.get('res.partner').browse(cursor, user, partner_id,
26 context=context)
27- if type == 'supplier':
28- account_id = part.property_account_payable.id
29- else:
30- account_id = part.property_account_receivable.id
31-
32- cursor.execute('SELECT sum(debit-credit) \
33+ if type == 'supplier':
34+ account_id = part.property_account_payable.id
35+ else:
36+ account_id = part.property_account_receivable.id
37+ res['value']['account_id'] = account_id
38+
39+ if not line or (line and not line[0].amount):
40+ res_users_obj = self.pool.get('res.users')
41+ res_currency_obj = self.pool.get('res.currency')
42+ company_currency_id = res_users_obj.browse(cursor, user, user,
43+ context=context).company_id.currency_id.id
44+ if not currency_id:
45+ currency_id = company_currency_id
46+
47+ cursor.execute('SELECT sum(debit-credit) \
48 FROM account_move_line \
49 WHERE (reconcile_id is null) \
50 AND partner_id = %s \
51 AND account_id=%s', (partner_id, account_id))
52- res = cursor.fetchone()
53- balance = res and res[0] or 0.0
54+ pgres = cursor.fetchone()
55+ balance = pgres and pgres[0] or 0.0
56
57- balance = res_currency_obj.compute(cursor, user, company_currency_id,
58+ balance = res_currency_obj.compute(cursor, user, company_currency_id,
59 currency_id, balance, context=context)
60- return {'value': {'amount': balance, 'account_id': account_id}}
61+ res['value']['amount'] = balance
62+ return res
63
64 def _reconcile_amount(self, cursor, user, ids, name, args, context=None):
65 if not ids: