Merge lp:~openerp-dev/openobject-server/6.0-opw-581385-cbi into lp:openobject-server/6.0

Proposed by Chris Biersbach (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/6.0-opw-581385-cbi
Merge into: lp:openobject-server/6.0
Diff against target: 34 lines (+7/-2)
1 file modified
bin/osv/expression.py (+7/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.0-opw-581385-cbi
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+134258@code.launchpad.net

Description of the change

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

To post a comment you must log in.

Unmerged revisions

3643. 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 'bin/osv/expression.py'
2--- bin/osv/expression.py 2011-01-17 08:41:08 +0000
3+++ bin/osv/expression.py 2012-11-14 08:17:22 +0000
4@@ -23,6 +23,7 @@
5 from tools import flatten, reverse_enumerate
6 import fields
7
8+NEGATIVE_TERM_OPERATORS = ('!=', '<>', 'not like', 'not ilike', 'not in')
9
10 class expression(object):
11 """
12@@ -365,16 +366,20 @@
13 ' AND type = %s'
14 instr = ' %s'
15 #Covering in,not in operators with operands (%s,%s) ,etc.
16+ if operator in NEGATIVE_TERM_OPERATORS:
17+ op = 'INTERSECT'
18+ else:
19+ op = 'UNION'
20 if operator in ['in','not in']:
21 instr = ','.join(['%s'] * len(right))
22 query1 += ' AND value ' + operator + ' ' +" (" + instr + ")" \
23- ') UNION (' \
24+ ') ' + op + ' (' \
25 ' SELECT id' \
26 ' FROM "' + working_table._table + '"' \
27 ' WHERE "' + left + '" ' + operator + ' ' +" (" + instr + "))"
28 else:
29 query1 += ' AND value ' + operator + instr + \
30- ') UNION (' \
31+ ') ' + op + ' (' \
32 ' SELECT id' \
33 ' FROM "' + working_table._table + '"' \
34 ' WHERE "' + left + '" ' + operator + instr + ")"