Merge lp:~openerp-dev/openobject-server/trunk-bug-1049653-translatable-unaccent-vmt into lp:openobject-server

Proposed by Vo Minh Thu
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/trunk-bug-1049653-translatable-unaccent-vmt
Merge into: lp:openobject-server
Diff against target: 73 lines (+36/-7)
2 files modified
openerp/addons/base/test/test_osv_expression.yml (+24/-2)
openerp/osv/expression.py (+12/-5)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-bug-1049653-translatable-unaccent-vmt
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+131206@code.launchpad.net
To post a comment you must log in.
4504. By Vo Minh Thu

[FIX] expression.py: add tests for unaccent use on translatable fields.

Revision history for this message
Vo Minh Thu (thu) wrote :

Fix similar to https://code.launchpad.net/~openerp-dev/openobject-server/6.1-bug-1049653-translatable-unaccent-vmt on the stable branch, but with added tests.

See the merge prop for stable (in the comment) for an additional test with ir_translation involved.

This can be merged once the other merge prop is done in stable and forward ported.

Unmerged revisions

4504. By Vo Minh Thu

[FIX] expression.py: add tests for unaccent use on translatable fields.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/test/test_osv_expression.yml'
2--- openerp/addons/base/test/test_osv_expression.yml 2012-10-19 04:28:56 +0000
3+++ openerp/addons/base/test/test_osv_expression.yml 2012-10-24 15:09:20 +0000
4@@ -445,10 +445,15 @@
5 !record {model: res.company, id: ymltest_unaccent_company}:
6 name: Hélène
7 -
8- Test the unaccent-enabled 'ilike'.
9+ Unaccent. Create a user with an accent in its name (which is inherits'd from res.partner).
10+-
11+ !record {model: res.users, id: ymltest_unaccent_user}:
12+ name: Pénélope
13+ login: pp
14+-
15+ Test the unaccent-enabled 'ilike' on company.
16 -
17 !python {model: res.company}: |
18- if self.pool.has_unaccent:
19 ids = self.search(cr, uid, [('name','ilike','Helene')], {})
20 assert ids == [ref('ymltest_unaccent_company')]
21 ids = self.search(cr, uid, [('name','ilike','hélène')], {})
22@@ -458,6 +463,23 @@
23 ids = self.search(cr, uid, [('name','not ilike','hélène')], {})
24 assert ref('ymltest_unaccent_company') not in ids
25 -
26+ Test the unaccent-enabled 'ilike' on user.
27+-
28+ !python {model: res.partner}: |
29+ self._columns['name'].translate = True
30+-
31+ Test the unaccent-enabled 'ilike' on user.
32+-
33+ !python {model: res.users}: |
34+ ids = self.search(cr, uid, [('name','ilike','Penelope')], {})
35+ assert ids == [ref('ymltest_unaccent_user')]
36+ ids = self.search(cr, uid, [('name','ilike','pénélope')], {})
37+ assert ids == [ref('ymltest_unaccent_user')]
38+ ids = self.search(cr, uid, [('name','not ilike','Penelope')], {})
39+ assert ref('ymltest_unaccent_user') not in ids
40+ ids = self.search(cr, uid, [('name','not ilike','pénélope')], {})
41+ assert ref('ymltest_unaccent_user') not in ids
42+-
43 Check that =like/=ilike expressions (no wildcard variants of like/ilike) are working on an untranslated field.
44 -
45 !python {model: res.partner }: |
46
47=== modified file 'openerp/osv/expression.py'
48--- openerp/osv/expression.py 2012-10-18 12:47:50 +0000
49+++ openerp/osv/expression.py 2012-10-24 15:09:20 +0000
50@@ -659,11 +659,18 @@
51 ' FROM "' + working_table._table + '"' \
52 ' WHERE "' + left + '" ' + sql_operator + ' ' +" (" + instr + "))"
53 else:
54- subselect += ' AND value ' + sql_operator + instr + \
55- ') UNION (' \
56- ' SELECT id' \
57- ' FROM "' + working_table._table + '"' \
58- ' WHERE "' + left + '" ' + sql_operator + instr + ")"
59+ if self.has_unaccent and sql_operator in ('ilike', 'not ilike'):
60+ subselect += ' AND unaccent(value) ' + sql_operator + ' unaccent(' + instr + \
61+ ')) UNION (' \
62+ ' SELECT id' \
63+ ' FROM "' + working_table._table + '"' \
64+ ' WHERE unaccent("' + left + '") ' + sql_operator + ' unaccent(' + instr + '))'
65+ else:
66+ subselect += ' AND value ' + sql_operator + instr + \
67+ ') UNION (' \
68+ ' SELECT id' \
69+ ' FROM "' + working_table._table + '"' \
70+ ' WHERE "' + left + '" ' + sql_operator + instr + ")"
71
72 params = [working_table._name + ',' + left,
73 context.get('lang', False) or 'en_US',