From f0151cd6e4c918dab3edfe5856371bae36d79b4e Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Wed, 5 Jun 2013 15:23:42 +0530 Subject: [PATCH] [FIX]Fixed the issue of search on tranlsated field, search on tranlsated field fails due to expression parsing which fetches ids from ir_translation as well as working table and UNION of this makes search fruitless, also search fails for in language other then english when you enter part of a string for the field to search. bzr revid: msh@openerp.com-20130605095342-314zfmttymx1k86a --- openerp/osv/expression.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index 58f35149ddd..b2184f73753 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -1020,37 +1020,32 @@ class expression(object): elif field.translate: need_wildcard = operator in ('like', 'ilike', 'not like', 'not ilike') sql_operator = {'=like': 'like', '=ilike': 'ilike'}.get(operator, operator) + instr = ' %s' if need_wildcard: right = '%%%s%%' % right - subselect = '( SELECT res_id' \ - ' FROM ir_translation' \ - ' WHERE name = %s' \ - ' AND lang = %s' \ - ' AND type = %s' - instr = ' %s' + select = 'WITH temp_'+working_model._table+' (id, name) as (' \ + 'SELECT wt.id, coalesce(it.value,wt.name) ' \ + 'FROM '+working_model._table+' wt ' \ + 'LEFT JOIN ir_translation it ON (it.name = %s and ' \ + 'it.lang = %s and ' \ + 'it.type = %s and ' \ + 'it.res_id = wt.id and ' \ + "it.value != '')" \ + ') ' #Covering in,not in operators with operands (%s,%s) ,etc. if sql_operator in ['in', 'not in']: instr = ','.join(['%s'] * len(right)) - subselect += ' AND value ' + sql_operator + ' ' + " (" + instr + ")" \ - ') UNION (' \ - ' SELECT id' \ - ' FROM "' + working_model._table + '"' \ - ' WHERE "' + left + '" ' + sql_operator + ' ' + " (" + instr + "))" + select += 'SELECT id FROM temp_'+working_model._table+' WHERE "name" '+sql_operator+' ('+instr+') order by name' else: - subselect += ' AND value ' + sql_operator + instr + \ - ') UNION (' \ - ' SELECT id' \ - ' FROM "' + working_model._table + '"' \ - ' WHERE "' + left + '" ' + sql_operator + instr + ")" + select += 'SELECT id FROM temp_'+working_model._table+' WHERE "name" '+sql_operator+' '+instr+' order by name' params = [working_model._name + ',' + left, context.get('lang', False) or 'en_US', 'model', right, - right, ] - push(create_substitution_leaf(leaf, ('id', 'inselect', (subselect, params)), working_model)) + push(create_substitution_leaf(leaf, ('id', 'inselect', (select, params)), working_model)) else: push_result(leaf)