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

Proposed by Vo Minh Thu
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/6.1-bug-1049653-translatable-unaccent-vmt
Merge into: lp:openobject-server/6.1
Diff against target: 27 lines (+12/-5)
1 file modified
openerp/osv/expression.py (+12/-5)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.1-bug-1049653-translatable-unaccent-vmt
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+131198@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Vo Minh Thu (thu) wrote :

Hello Reviewer,

I think it is safe to include this merge prop. in the stable branch. I run some tests and the `if..else` clause is obvious: the else is identical to the original code, and the if depends clearly on the --unaccent flag being given (so in the worst case it should affect only --unaccent users).

If you want to try for yourself the tests, you can paste this code in the product.product YAML tests (i.e. I targeted a translatable field which was located on an inherits'd model):

-
    Unaccent. Create a product with an accent in its name.
-
    !record {model: product.product, id: ymltest_unaccent_product}:
        name: Café
-
    Test the unaccent-enabled 'ilike' on product.
-
    !python {model: product.product}: |
            ids = self.search(cr, uid, [('name','ilike','Cafe')], {})
            assert ids == [ref('ymltest_unaccent_product')], "unaccent on product (1)"
            ids = self.search(cr, uid, [('name','ilike','café')], {})
            assert ids == [ref('ymltest_unaccent_product')], "unaccent on product (2)"
            ids = self.search(cr, uid, [('name','not ilike','Cafe')], {})
            assert ref('ymltest_unaccent_product') not in ids, "unaccent on product (3)"
            ids = self.search(cr, uid, [('name','not ilike','café')], {})
            assert ref('ymltest_unaccent_product') not in ids, "unaccent on product (4)"
-
    Unaccent. Create a product.
-
    !record {model: product.product, id: ymltest_unaccent_product_2}:
        name: Goat
-
    Unaccent. Create a language.
-
    !record {model: res.lang, id: ymltest_lang}:
        name: French
        code: fr_FR
        translatable: True
-
    Unaccent. Create a translation.
-
    !record {model: ir.translation, id: ymltest_translation}:
        name: 'product.template,name'
        lang: fr_FR
        src: 'Goat'
        value: 'Chèvre'
        type: 'model'
        res_id: !eval ref('ymltest_unaccent_product_2')
-
    Test the unaccent-enabled 'ilike' with a translated product name.
-
    !python {model: product.product}: |
            ids = self.search(cr, uid, [('name','ilike','chevre')], context={'lang': 'fr_FR'})
            assert ids == [ref('ymltest_unaccent_product_2')], "translated unaccent on product (1)"

Unmerged revisions

4294. By Vo Minh Thu

[FIX]: expression.py: The unaccent call was missing for translatable 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-01-24 12:42:52 +0000
3+++ openerp/osv/expression.py 2012-10-24 14:36:22 +0000
4@@ -637,11 +637,18 @@
5 ' FROM "' + working_table._table + '"' \
6 ' WHERE "' + left + '" ' + sql_operator + ' ' +" (" + instr + "))"
7 else:
8- subselect += ' AND value ' + sql_operator + instr + \
9- ') UNION (' \
10- ' SELECT id' \
11- ' FROM "' + working_table._table + '"' \
12- ' WHERE "' + left + '" ' + sql_operator + instr + ")"
13+ if self.has_unaccent and sql_operator in ('ilike', 'not ilike'):
14+ subselect += ' AND unaccent(value) ' + sql_operator + ' unaccent(' + instr + \
15+ ')) UNION (' \
16+ ' SELECT id' \
17+ ' FROM "' + working_table._table + '"' \
18+ ' WHERE unaccent("' + left + '") ' + sql_operator + ' unaccent(' + instr + '))'
19+ else:
20+ subselect += ' AND value ' + sql_operator + instr + \
21+ ') UNION (' \
22+ ' SELECT id' \
23+ ' FROM "' + working_table._table + '"' \
24+ ' WHERE "' + left + '" ' + sql_operator + instr + ")"
25
26 params = [working_table._name + ',' + left,
27 context.get('lang', False) or 'en_US',