Merge lp:~openerp-dev/openobject-server/trunk-opw-581385-port-cha into lp:openobject-server

Proposed by Ajay Chauhan(OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/trunk-opw-581385-port-cha
Merge into: lp:openobject-server
Diff against target: 27 lines (+7/-3)
1 file modified
openerp/osv/expression.py (+7/-3)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-opw-581385-port-cha
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+138428@code.launchpad.net

Description of the change

Hello,

The bug that was encountered: When using the negative operators in advanced filters, wrong results were shown when the language was not set to english

The reason: If you search, for example, for countries that are not "Belgique", a union between the countries that do not have "Belgique" as original value and that do not have "Belgique" as french translation is made. This is incorrect, since it will return all the countries. This was done to allow the user to search using both the original value "Belgium" and the translated value "Belgique", and it works fine for the positive operators (in which case the union makes perfect sense), but not for the negative operators.

The fix: When using negative operators, an intersection must be used instead of a union.
-> Countries that are called "Belgique" OR whose translated value is "Belgique": Union
-> Countries that are not called "Belgique" AND whose translation is not "Belgique": Intersection
-> In logic: NOT(a OR b) == NOT a AND not b

Code is forward port from 6.1

Thanks,
Ajay Chauhan

To post a comment you must log in.
4644. By Ajay Chauhan(OpenERP)

[MERGE] merge with lp:openobject-server

Unmerged revisions

4644. By Ajay Chauhan(OpenERP)

[MERGE] merge with lp:openobject-server

4643. By Chris Biersbach (OpenERP)

[FIX] This fixes incorrect behavior of of advanced search filters containing negative operators on translated fields

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-12-07 16:09:33 +0000
3+++ openerp/osv/expression.py 2012-12-13 06:10:55 +0000
4@@ -1026,16 +1026,20 @@
5 ' AND type = %s'
6 instr = ' %s'
7 #Covering in,not in operators with operands (%s,%s) ,etc.
8+ if sql_operator in NEGATIVE_TERM_OPERATORS:
9+ op = 'INTERSECT'
10+ else:
11+ op = 'UNION'
12 if sql_operator in ['in', 'not in']:
13 instr = ','.join(['%s'] * len(right))
14- subselect += ' AND value ' + sql_operator + ' ' + " (" + instr + ")" \
15- ') UNION (' \
16+ subselect += ' AND value ' + sql_operator + ' ' +" (" + instr + ")" \
17+ ') ' + op + ' (' \
18 ' SELECT id' \
19 ' FROM "' + working_model._table + '"' \
20 ' WHERE "' + left + '" ' + sql_operator + ' ' + " (" + instr + "))"
21 else:
22 subselect += ' AND value ' + sql_operator + instr + \
23- ') UNION (' \
24+ ') ' + op + ' (' \
25 ' SELECT id' \
26 ' FROM "' + working_model._table + '"' \
27 ' WHERE "' + left + '" ' + sql_operator + instr + ")"