From 694693905a78a63e609b8bbd00db59d49e4ef536 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Fri, 10 Jun 2011 19:06:58 +0530 Subject: [PATCH] add yml test-case for =like and =ilike operator lp bug: https://launchpad.net/bugs/788106 fixed bzr revid: nco@tinyerp.com-20110610133658-z4avh4z60moecyde --- .../addons/base/test/test_osv_expression.yml | 26 +++++++++++++++++++ openerp/osv/expression.py | 8 +++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/openerp/addons/base/test/test_osv_expression.yml b/openerp/addons/base/test/test_osv_expression.yml index 4916fe06203..0e88f1ac022 100644 --- a/openerp/addons/base/test/test_osv_expression.yml +++ b/openerp/addons/base/test/test_osv_expression.yml @@ -111,3 +111,29 @@ res_ids.sort() assert res_ids == all_ids, "Searching against empty set failed, returns %r" % res_ids +- + Check that =like expressions is working without translation field +- + !python {model: res.partner }: | + all_ids = self.search(cr, uid, [('name', '=like', 'Ax')]) + assert len(all_ids) <= 1,"with =like operator without translation field, returns" + +- + Check that =ilike expression is working without translation field +- + !python {model: res.partner }: | + all_ids = self.search(cr, uid, [('name', '=ilike', 'Ax')]) + assert len(all_ids) <= 2,"with =ilike operator without translation field, returns" +- + Check that =like expression is working with translation field +- + !python {model: res.country }: | + all_ids = self.search(cr, uid, [('name', '=like', 'Ind')]) + assert len(all_ids) <= 3,"with =like operator with translation field, returns" + +- + Check that =ilike expression is working with translation field +- + !python {model: res.country }: | + all_ids = self.search(cr, uid, [('name', '=ilike', 'Ind')]) + assert len(all_ids) <= 3,"with =ilike operator with translation field, returns" \ No newline at end of file diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index 1922d5e8388..515f1390491 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -353,11 +353,10 @@ class expression(object): self.__exp[i] = tuple(self.__exp[i]) if field.translate: + operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator) if operator in ('like', 'ilike', 'not like', 'not ilike'): right = '%%%s%%' % right - - operator = operator == '=like' and 'like' or operator - + query1 = '( SELECT res_id' \ ' FROM ir_translation' \ ' WHERE name = %s' \ @@ -451,8 +450,9 @@ class expression(object): query = '%s.id %s %%s' % (table._table, operator) params = right else: + operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator) like = operator in ('like', 'ilike', 'not like', 'not ilike') - + op = {'=like':'like','=ilike':'ilike'}.get(operator,operator) if left in table._columns: format = like and '%s' or table._columns[left]._symbol_set[0]