From 2da2a984497bfab2280278a20a4e09333be86d98 Mon Sep 17 00:00:00 2001 From: "Anup (OpenERP)" Date: Fri, 27 Aug 2010 20:33:27 +0530 Subject: [PATCH] [FIX] account : fixed _search_amount() method to allow operators like <, >, =, !=, in and not in bzr revid: ach@tinyerp.com-20100827150327-mte99e0zvpxdbb0u --- addons/account/account.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index f0884044fcf..eefe815bf97 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1051,21 +1051,25 @@ class account_move(osv.osv): return result def _search_amount(self, cr, uid, obj, name, args, context): - ids = [] - cr.execute('select move_id,sum(debit) from account_move_line group by move_id') - result = dict(cr.fetchall()) - - for item in args: - if item[1] == '>=': - res = [('id', 'in', [k for k,v in result.iteritems() if v >= item[2]])] + ids = set() + for cond in args: + amount = cond[2] + if isinstance(cond[2],(list,tuple)): + if cond[1] in ['in','not in']: + amount = tuple(cond[2]) + else: + continue else: - res = [('id', 'in', [k for k,v in result.iteritems() if v <= item[2]])] - ids += res - - if not ids: - return [('id', '>', '0')] - - return ids + if cond[1] in ['=like', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of']: + continue + + cr.execute("select move_id from account_move_line group by move_id having sum(debit) %s %%s" % (cond[1]) ,(amount,)) + res_ids = set(id[0] for id in cr.fetchall()) + ids = ids and (ids & res_ids) or res_ids + if ids: + return [('id','in',tuple(ids))] + else: + return [('id', '=', '0')] _columns = { 'name': fields.char('Number', size=64, required=True),