[FIX] expression: translated search as params are flatten, we need to expand "%s" placeholders when using the `in` operator
bzr revid: chs@openerp.com-20140402112730-eoqxt0pu7lvcq5yg
This commit is contained in:
parent
4fe43d9ac6
commit
19993ab1d5
|
@ -439,5 +439,18 @@ class test_expression(common.TransactionCase):
|
|||
partner_parent_id_col._auto_join = False
|
||||
state_country_id_col._auto_join = False
|
||||
|
||||
def test_translate_search(self):
|
||||
Country = self.registry('res.country')
|
||||
be = self.ref('base.be')
|
||||
domains = [
|
||||
[('name', '=', 'Belgium')],
|
||||
[('name', 'ilike', 'Belgi')],
|
||||
[('name', 'in', ['Belgium', 'Care Bears'])],
|
||||
]
|
||||
|
||||
for domain in domains:
|
||||
ids = Country.search(self.cr, self.uid, domain)
|
||||
self.assertListEqual([be], ids)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
||||
|
|
|
@ -1032,18 +1032,19 @@ class expression(object):
|
|||
sql_operator = sql_operator[4:] if sql_operator[:3] == 'not' else '='
|
||||
inselect_operator = 'not inselect'
|
||||
|
||||
if sql_operator == 'in':
|
||||
right = tuple(right)
|
||||
|
||||
if self.has_unaccent and sql_operator.endswith('like'):
|
||||
trans_left = 'unaccent(value)'
|
||||
left = 'unaccent("%s")' % (left,)
|
||||
instr = 'unaccent(%s)'
|
||||
else:
|
||||
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,)
|
||||
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
|
||||
|
@ -1058,12 +1059,13 @@ class expression(object):
|
|||
""".format(trans_left=trans_left, operator=sql_operator,
|
||||
right=instr, table=working_model._table, left=left)
|
||||
|
||||
params = [working_model._name + ',' + field,
|
||||
context.get('lang', False) or 'en_US',
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue