Merge lp:~openerp-dev/openobject-server/6.1-opw-592890TranlationFieldSearch-msh into lp:openobject-server/6.1

Proposed by Mohammed Shekha(Open ERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/6.1-opw-592890TranlationFieldSearch-msh
Merge into: lp:openobject-server/6.1
Diff against target: 57 lines (+15/-23)
1 file modified
openerp/osv/expression.py (+15/-23)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.1-opw-592890TranlationFieldSearch-msh
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Pending
Naresh(OpenERP) Pending
Review via email: mp+167496@code.launchpad.net

Description of the change

Hello,

Please go through the description of lp:~openerp-dev/openobject-server/7.0-opw-592890SearchOnTranlslatebleField-msh.

Same issue persist in stable 6.1 as well as in stable version 7.0.

Thanks.

To post a comment you must log in.

Unmerged revisions

4352. By Mohammed Shekha<email address hidden>

[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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/expression.py'
2--- openerp/osv/expression.py 2012-01-24 12:42:52 +0000
3+++ openerp/osv/expression.py 2013-06-05 10:13:29 +0000
4@@ -619,38 +619,30 @@
5 if field.translate:
6 need_wildcard = operator in ('like', 'ilike', 'not like', 'not ilike')
7 sql_operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator)
8+ instr = ' %s'
9 if need_wildcard:
10 right = '%%%s%%' % right
11
12- subselect = '( SELECT res_id' \
13- ' FROM ir_translation' \
14- ' WHERE name = %s' \
15- ' AND lang = %s' \
16- ' AND type = %s'
17- instr = ' %s'
18- #Covering in,not in operators with operands (%s,%s) ,etc.
19+ select = 'WITH temp_'+working_table._table+' (id, name) as (' \
20+ 'SELECT wt.id, coalesce(it.value,wt.name) ' \
21+ 'FROM '+working_table._table+' wt ' \
22+ 'LEFT JOIN ir_translation it ON (it.name = %s and ' \
23+ 'it.lang = %s and ' \
24+ 'it.type = %s and ' \
25+ 'it.res_id = wt.id and ' \
26+ "it.value != '' )" \
27+ ') '
28 if sql_operator in ['in','not in']:
29 instr = ','.join(['%s'] * len(right))
30- subselect += ' AND value ' + sql_operator + ' ' +" (" + instr + ")" \
31- ') UNION (' \
32- ' SELECT id' \
33- ' FROM "' + working_table._table + '"' \
34- ' WHERE "' + left + '" ' + sql_operator + ' ' +" (" + instr + "))"
35+ select += 'SELECT id FROM temp_'+working_table._table+' WHERE "name" '+sql_operator+' ('+instr+') order by name'
36 else:
37- subselect += ' AND value ' + sql_operator + instr + \
38- ') UNION (' \
39- ' SELECT id' \
40- ' FROM "' + working_table._table + '"' \
41- ' WHERE "' + left + '" ' + sql_operator + instr + ")"
42-
43+ select += 'SELECT id FROM temp_'+working_table._table+' WHERE "name" '+sql_operator+' '+instr+' order by name'
44 params = [working_table._name + ',' + left,
45 context.get('lang', False) or 'en_US',
46 'model',
47- right,
48- right,
49- ]
50-
51- self.__exp[i] = ('id', 'inselect', (subselect, params))
52+ right
53+ ]
54+ self.__exp[i] = ('id', 'inselect', (select, params))
55
56 def __leaf_to_sql(self, leaf, table):
57 left, operator, right = leaf