[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:
Christophe Simonis 2014-04-02 13:27:30 +02:00
parent 4fe43d9ac6
commit 19993ab1d5
2 changed files with 27 additions and 12 deletions

View File

@ -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()

View File

@ -1032,17 +1032,18 @@ 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)
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)'
else:
trans_left = 'value'
left = '"%s"' % (left,)
instr = '%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
@ -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',
'model',
right,
right,
]
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: