From 868a364138502cfc74df60ae50e3cc82e27d4d03 Mon Sep 17 00:00:00 2001 From: ced <> Date: Mon, 30 Apr 2007 18:50:52 +0000 Subject: [PATCH] CLIENT,KERNEL: allow search for translate fields bzr revid: ced-d1365bed850a3ac1faf21438dd3c8bb24d8cb3bf --- bin/osv/orm.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 61d5f298d76..acb2bd092fc 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1362,7 +1362,7 @@ class orm(object): qu1.append(' (1=0)') return (qu1,qu2) - def search(self, cr, user, args, offset=0, limit=None, order=None): + def search(self, cr, user, args, offset=0, limit=None, order=None, context={}, translate=False): # if the object has a field named 'active', filter out all inactive # records unless they were explicitely asked for if 'active' in self._columns: @@ -1472,7 +1472,16 @@ class orm(object): if field._fnct_search: args.extend(field.search(cr, user, self, arg[0][0], arg)) else: - args[i] += (table,) + if field.translate and translate and context.get('lang', False) and context['lang'] != 'en_EN': + if args[i][1] in ('like', 'ilike'): + args[i][2] = '%%%s%%' % args[i][2] + cr.execute('select res_id from ir_translation where name = %s and lang = %s and type = %s and value '+args[i][1]+' %s', (table._name+','+args[i][0], context['lang'], 'model', args[i][2])) + ids = map(lambda x: x[0], cr.fetchall()) + cr.execute('select id from '+table._table+' where '+args[i][0]+' '+args[i][1]+' %s', (args[i][2],)) + ids += map(lambda x: x[0], cr.fetchall()) + args[i] = ('id', 'in', ids, table) + else: + args[i] += (table,) i+=1 args.extend(joins)