[MERGE] forward port of branch saas-2 up to revid 5024 chs@openerp.com-20140402112825...
authorChristophe Simonis <chs@openerp.com>
Wed, 2 Apr 2014 11:48:23 +0000 (13:48 +0200)
committerChristophe Simonis <chs@openerp.com>
Wed, 2 Apr 2014 11:48:23 +0000 (13:48 +0200)
bzr revid: chs@openerp.com-20140402093016-rcl15e5vpdj7ishv
bzr revid: chs@openerp.com-20140402114823-4mncr059d9ms8v3t

1  2 
openerp/osv/expression.py
openerp/osv/fields.py

@@@ -1030,33 -1031,40 +1031,40 @@@ class expression(object)
                          sql_operator = sql_operator[4:] if sql_operator[:3] == 'not' else '='
                          inselect_operator = 'not inselect'
  
-                     subselect = '( SELECT res_id'          \
-                              '    FROM ir_translation'  \
-                              '   WHERE name = %s'       \
-                              '     AND lang = %s'       \
-                              '     AND type = %s'
-                     instr = ' %s'
-                     #Covering in,not in operators with operands (%s,%s) ,etc.
-                     if sql_operator == 'in':
-                         instr = ','.join(['%s'] * len(right))
-                         subselect += '     AND value ' + sql_operator + ' ' + " (" + instr + ")"   \
-                              ') UNION ('                \
-                              '  SELECT id'              \
-                              '    FROM "' + working_model._table + '"'       \
-                              '   WHERE "' + left + '" ' + sql_operator + ' ' + " (" + instr + "))"
-                     else:
-                         subselect += '     AND value ' + sql_operator + instr +   \
-                              ') UNION ('                \
-                              '  SELECT id'              \
-                              '    FROM "' + working_model._table + '"'       \
-                              '   WHERE "' + left + '" ' + sql_operator + instr + ")"
-                     params = [working_model._name + ',' + left,
-                               context.get('lang', False) or 'en_US',
-                               'model',
-                               right,
-                               right,
-                              ]
+                     trans_left = 'value'
+                     left = '"%s"' % (left,)
+                     instr = '%s'
+                     if self.has_unaccent and sql_operator.endswith('like'):
+                         assert isinstance(right, basestring)
+                         trans_left = 'unaccent(value)'
 -                        left = 'unaccent(%s)' % (left,)
++                        left = 'unaccent("%s")' % (left,)
+                         instr = 'unaccent(%s)'
+                     elif sql_operator == 'in':
+                         # params will be flatten by to_sql() => expand the placeholders
+                         instr = '(%s)' % ', '.join(['%s'] * len(right))
+                     subselect = """(SELECT res_id
+                                       FROM ir_translation
+                                      WHERE name = %s
+                                        AND lang = %s
+                                        AND type = %s
+                                        AND {trans_left} {operator} {right}
+                                    ) UNION (
+                                     SELECT id
+                                       FROM "{table}"
+                                      WHERE {left} {operator} {right}
+                                    )
+                                 """.format(trans_left=trans_left, operator=sql_operator,
+                                            right=instr, table=working_model._table, left=left)
+                     params = (
+                         working_model._name + ',' + field,
+                         context.get('lang') or 'en_US',
+                         'model',
+                         right,
+                         right,
+                     )
                      push(create_substitution_leaf(leaf, ('id', inselect_operator, (subselect, params)), working_model))
  
                  else:
Simple merge