From 10794f74d27813cfeeb1b61772d5caf4c05ede1e Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Sat, 14 Aug 2010 11:07:43 +0530 Subject: [PATCH] [IMP] Account: Onchange of partner on bank statement lines now dont fill amount on line bzr revid: mra@mra-laptop-20100814053743-fsqvt4ic4mjsor46 --- addons/account/account_bank_statement.py | 56 +++++++----------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 59637edb546..8a8f5556aff 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -20,9 +20,9 @@ ############################################################################## import time + import netsvc from osv import fields, osv - from tools.misc import currency from tools.translate import _ import decimal_precision as dp @@ -52,13 +52,13 @@ class account_bank_statement(osv.osv): journal_pool = self.pool.get('account.journal') journal_type = context.get('journal_type', False) journal_id = False - + if journal_type: ids = journal_pool.search(cr, uid, [('type', '=', journal_type)]) if ids: journal_id = ids[0] - - return journal_id + + return journal_id def _default_balance_start(self, cr, uid, context={}): cr.execute('select id from account_bank_statement where journal_id=%s order by date desc limit 1', (1,)) @@ -126,7 +126,7 @@ class account_bank_statement(osv.osv): currency_id = res[statement_id] res[statement_id] = (currency_id, currency_names[currency_id]) return res - + _order = "date desc" _name = "account.bank.statement" _description = "Bank Statement" @@ -185,7 +185,7 @@ class account_bank_statement(osv.osv): context.update({ 'period_id':pids[0] }) - + return { 'value':res, 'context':context, @@ -194,7 +194,7 @@ class account_bank_statement(osv.osv): def button_dummy(self, cr, uid, ids, context={}): self.write(cr, uid, ids, {}, context) return True - + def button_confirm_bank(self, cr, uid, ids, context={}): done = [] res_currency_obj = self.pool.get('res.currency') @@ -370,7 +370,7 @@ class account_bank_statement(osv.osv): if st.journal_id.entry_posted: account_move_obj.write(cr, uid, [move_id], {'state':'posted'}) - + self.log(cr, uid, st.id, 'Statement %s is confirmed and entries are created.' % st.name) done.append(st.id) @@ -610,45 +610,22 @@ account_bank_statement_reconcile_line() class account_bank_statement_line(osv.osv): - def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context={}): + def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None): res = {'value': {}} - + obj_partner = self.pool.get('res.partner') + if context is None: + context = {} if not partner_id: return res + line = self.browse(cursor, user, line_id) - if not line or (line and not line[0].account_id): - part = self.pool.get('res.partner').browse(cursor, user, partner_id, - context=context) + part = obj_partner.browse(cursor, user, partner_id, context=context) if type == 'supplier': account_id = part.property_account_payable.id else: account_id = part.property_account_receivable.id res['value']['account_id'] = account_id - - if not line or (line and not line[0].amount): - res_users_obj = self.pool.get('res.users') - res_currency_obj = self.pool.get('res.currency') - company_currency_id = res_users_obj.browse(cursor, user, user, - context=context).company_id.currency_id.id - if not currency_id: - currency_id = company_currency_id - - cursor.execute('SELECT sum(debit-credit) \ - FROM account_move_line \ - WHERE (reconcile_id is null) \ - AND partner_id = %s \ - AND account_id=%s', (partner_id, account_id)) - pgres = cursor.fetchone() - balance = pgres and pgres[0] or 0.0 - - balance = res_currency_obj.compute(cursor, user, company_currency_id, - currency_id, balance, context=context) - res['value']['amount'] = balance - - if context.get('amount', 0) > 0: - res['value']['amount'] = context.get('amount') - return res def _reconcile_amount(self, cursor, user, ids, name, args, context=None): @@ -707,7 +684,4 @@ class account_bank_statement_line(osv.osv): account_bank_statement_line() - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file