[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
This commit is contained in:
+13
-18
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user