[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
|
partner_parent_id_col._auto_join = False
|
||||||
state_country_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__':
|
if __name__ == '__main__':
|
||||||
unittest2.main()
|
unittest2.main()
|
||||||
|
|
|
@ -1032,17 +1032,18 @@ class expression(object):
|
||||||
sql_operator = sql_operator[4:] if sql_operator[:3] == 'not' else '='
|
sql_operator = sql_operator[4:] if sql_operator[:3] == 'not' else '='
|
||||||
inselect_operator = 'not inselect'
|
inselect_operator = 'not inselect'
|
||||||
|
|
||||||
if sql_operator == 'in':
|
trans_left = 'value'
|
||||||
right = tuple(right)
|
left = '"%s"' % (left,)
|
||||||
|
instr = '%s'
|
||||||
|
|
||||||
if self.has_unaccent and sql_operator.endswith('like'):
|
if self.has_unaccent and sql_operator.endswith('like'):
|
||||||
|
assert isinstance(right, basestring)
|
||||||
trans_left = 'unaccent(value)'
|
trans_left = 'unaccent(value)'
|
||||||
left = 'unaccent("%s")' % (left,)
|
left = 'unaccent("%s")' % (left,)
|
||||||
instr = 'unaccent(%s)'
|
instr = 'unaccent(%s)'
|
||||||
else:
|
elif sql_operator == 'in':
|
||||||
trans_left = 'value'
|
# params will be flatten by to_sql() => expand the placeholders
|
||||||
left = '"%s"' % (left,)
|
instr = '(%s)' % ', '.join(['%s'] * len(right))
|
||||||
instr = '%s'
|
|
||||||
|
|
||||||
subselect = """(SELECT res_id
|
subselect = """(SELECT res_id
|
||||||
FROM ir_translation
|
FROM ir_translation
|
||||||
|
@ -1058,12 +1059,13 @@ class expression(object):
|
||||||
""".format(trans_left=trans_left, operator=sql_operator,
|
""".format(trans_left=trans_left, operator=sql_operator,
|
||||||
right=instr, table=working_model._table, left=left)
|
right=instr, table=working_model._table, left=left)
|
||||||
|
|
||||||
params = [working_model._name + ',' + field,
|
params = (
|
||||||
context.get('lang', False) or 'en_US',
|
working_model._name + ',' + field,
|
||||||
'model',
|
context.get('lang') or 'en_US',
|
||||||
right,
|
'model',
|
||||||
right,
|
right,
|
||||||
]
|
right,
|
||||||
|
)
|
||||||
push(create_substitution_leaf(leaf, ('id', inselect_operator, (subselect, params)), working_model))
|
push(create_substitution_leaf(leaf, ('id', inselect_operator, (subselect, params)), working_model))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue