Merge lp:~openerp-dev/openobject-server/7.0-opw-592890SearchOnTranlslatebleField-msh into lp:openobject-server/7.0

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

Description of the change

Hello,

Fixed the issue of no other operator supported in advance search(except contains) if language is other then english for translated field.

Demo:- Install german language -> use german language -> go to supplier listview(to face this issue add/show country field in listview), add advance filter with Land, enthalt nicht(doesn't contains) and value(say for example Belgien)
Result: It doesn't give resule according to filter applied, even though we filter that doesn't contains Belgien still it will give records with Belgien.

Reason: It is due to expression parsing, if field is translateable then we make UNION of res_id from it_translation and same string we search in current working table(i.e. records from currenct working table where filed value not Belgien, in working table field value always be in English source language).

Fixed the issue by making virtual table using WITH query with LEFT JOIN ir_tranlsations, this way we will be able to search on translated field with whole string as well as part of a tranlsated string.

Thanks.

To post a comment you must log in.

Unmerged revisions

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 2013-05-14 10:33:33 +0000
3+++ openerp/osv/expression.py 2013-06-05 10:10:37 +0000
4@@ -1020,37 +1020,32 @@
5 elif 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+ select = 'WITH temp_'+working_model._table+' (id, name) as (' \
19+ 'SELECT wt.id, coalesce(it.value,wt.name) ' \
20+ 'FROM '+working_model._table+' wt ' \
21+ 'LEFT JOIN ir_translation it ON (it.name = %s and ' \
22+ 'it.lang = %s and ' \
23+ 'it.type = %s and ' \
24+ 'it.res_id = wt.id and ' \
25+ "it.value != '')" \
26+ ') '
27 #Covering in,not in operators with operands (%s,%s) ,etc.
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_model._table + '"' \
34- ' WHERE "' + left + '" ' + sql_operator + ' ' + " (" + instr + "))"
35+ select += 'SELECT id FROM temp_'+working_model._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_model._table + '"' \
41- ' WHERE "' + left + '" ' + sql_operator + instr + ")"
42+ select += 'SELECT id FROM temp_'+working_model._table+' WHERE "name" '+sql_operator+' '+instr+' order by name'
43
44 params = [working_model._name + ',' + left,
45 context.get('lang', False) or 'en_US',
46 'model',
47 right,
48- right,
49 ]
50- push(create_substitution_leaf(leaf, ('id', 'inselect', (subselect, params)), working_model))
51+ push(create_substitution_leaf(leaf, ('id', 'inselect', (select, params)), working_model))
52
53 else:
54 push_result(leaf)