diff options
| author | Olivier Dony <odo@openerp.com> | 2011-09-22 00:52:25 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2011-09-22 00:52:25 +0200 |
| commit | c856d70bf5cded97c7b9b496e8f78f5f435e4dfc (patch) | |
| tree | 1c58d9231f711cccfa7aa3cd7ec60de1736e1189 | |
| parent | 6652943cd24d02fa7286d95d30fb3823d6300214 (diff) | |
| parent | 886b7407dedc7256492c78d1e7873a0e6efed3be (diff) | |
[MERGE] sync latest trunk, including fixes for =like/=ilike
bzr revid: odo@openerp.com-20110921225225-zk98p2w1asoi2csl
| -rw-r--r-- | openerp/addons/base/res/res_currency_view.xml | 13 | ||||
| -rw-r--r-- | openerp/addons/base/test/test_osv_expression.yml | 20 | ||||
| -rw-r--r-- | openerp/osv/expression.py | 35 |
3 files changed, 41 insertions, 27 deletions
diff --git a/openerp/addons/base/res/res_currency_view.xml b/openerp/addons/base/res/res_currency_view.xml index dd2c83a630f..bf54887da0b 100644 --- a/openerp/addons/base/res/res_currency_view.xml +++ b/openerp/addons/base/res/res_currency_view.xml @@ -2,6 +2,18 @@ <openerp> <data> + <record id="view_currency_search" model="ir.ui.view"> + <field name="name">res.currency.search</field> + <field name="model">res.currency</field> + <field name="type">search</field> + <field name="arch" type="xml"> + <search string="Currencies"> + <field name="name"/> + <field name="active"/> + </search> + </field> + </record> + <record id="view_currency_tree" model="ir.ui.view"> <field name="name">res.currency.tree</field> <field name="model">res.currency</field> @@ -62,6 +74,7 @@ <field name="res_model">res.currency</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> + <field name="search_view_id" ref="view_currency_search"/> </record> <menuitem action="action_currency_form" id="menu_action_currency_form" parent="menu_localisation" sequence="3"/> diff --git a/openerp/addons/base/test/test_osv_expression.yml b/openerp/addons/base/test/test_osv_expression.yml index ac2542d54e0..5ecab625911 100644 --- a/openerp/addons/base/test/test_osv_expression.yml +++ b/openerp/addons/base/test/test_osv_expression.yml @@ -453,18 +453,18 @@ ids = self.search(cr, uid, [('name','not ilike','hélène')], {}) assert ref('ymltest_unaccent_company') not in ids - - Check that =like/=ilike expressions are working with an untranslated field. + Check that =like/=ilike expressions (no wildcard variants of like/ilike) are working on an untranslated field. - !python {model: res.partner }: | - all_ids = self.search(cr, uid, [('name', '=like', 'Ax')]) - assert len(all_ids) == 1, "It should have 1 record !" - all_ids = self.search(cr, uid, [('name', '=ilike', 'Ax')]) - assert len(all_ids) == 2, "It should have 2 records !" + all_ids = self.search(cr, uid, [('name', '=like', 'A_e_or')]) + assert len(all_ids) == 1, "Must match one partner (Axelor), got %r"%all_ids + all_ids = self.search(cr, uid, [('name', '=ilike', 'm_____')]) + assert len(all_ids) == 1, "Must match *only* one partner (Maxtor), got %r"%all_ids - - Check that =like/=ilike expressions are working with a translated field. + Check that =like/=ilike expressions (no wildcard variants of like/ilike) are working on translated field. - !python {model: res.country }: | - all_ids = self.search(cr, uid, [('name', '=like', 'Ind')]) - assert len(all_ids) == 3, "It should have 3 records !" - all_ids = self.search(cr, uid, [('name', '=ilike', 'Ind')]) - assert len(all_ids) == 3, "It should have 3 records !" + all_ids = self.search(cr, uid, [('name', '=like', 'Ind__')]) + assert len(all_ids) == 1, "Must match India only, got %r"%all_ids + all_ids = self.search(cr, uid, [('name', '=ilike', 'z%')]) + assert len(all_ids) == 3, "Must match only countries with names starting with Z (currently 3), got %r"%all_ids diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index deb0af2e951..4d558bdb619 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -614,8 +614,9 @@ 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'): + need_wildcard = operator in ('like', 'ilike', 'not like', 'not ilike') + sql_operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator) + if need_wildcard: right = '%%%s%%' % right subselect = '( SELECT res_id' \ @@ -625,19 +626,19 @@ class expression(object): ' AND type = %s' instr = ' %s' #Covering in,not in operators with operands (%s,%s) ,etc. - if operator in ['in','not in']: + if sql_operator in ['in','not in']: instr = ','.join(['%s'] * len(right)) - subselect += ' AND value ' + operator + ' ' +" (" + instr + ")" \ + subselect += ' AND value ' + sql_operator + ' ' +" (" + instr + ")" \ ') UNION (' \ ' SELECT id' \ ' FROM "' + working_table._table + '"' \ - ' WHERE "' + left + '" ' + operator + ' ' +" (" + instr + "))" + ' WHERE "' + left + '" ' + sql_operator + ' ' +" (" + instr + "))" else: - subselect += ' AND value ' + operator + instr + \ + subselect += ' AND value ' + sql_operator + instr + \ ') UNION (' \ ' SELECT id' \ ' FROM "' + working_table._table + '"' \ - ' WHERE "' + left + '" ' + operator + instr + ")" + ' WHERE "' + left + '" ' + sql_operator + instr + ")" params = [working_table._name + ',' + left, context.get('lang', False) or 'en_US', @@ -734,23 +735,23 @@ class expression(object): params = right else: - like = operator in ('like', 'ilike', 'not like', 'not ilike') + need_wildcard = operator in ('like', 'ilike', 'not like', 'not ilike') + sql_operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator) - op = {'=like':'like','=ilike':'ilike'}.get(operator, operator) if left in table._columns: - format = like and '%s' or table._columns[left]._symbol_set[0] - if self.has_unaccent and op in ('ilike', 'not ilike'): - query = '(unaccent(%s."%s") %s unaccent(%s))' % (table._table, left, op, format) + format = need_wildcard and '%s' or table._columns[left]._symbol_set[0] + if self.has_unaccent and sql_operator in ('ilike', 'not ilike'): + query = '(unaccent(%s."%s") %s unaccent(%s))' % (table._table, left, sql_operator, format) else: - query = '(%s."%s" %s %s)' % (table._table, left, op, format) + query = '(%s."%s" %s %s)' % (table._table, left, sql_operator, format) else: - if self.has_unaccent and op in ('ilike', 'not ilike'): - query = "(unaccent(%s.\"%s\") %s unaccent('%s'))" % (table._table, left, op, right) + if self.has_unaccent and sql_operator in ('ilike', 'not ilike'): + query = "(unaccent(%s.\"%s\") %s unaccent('%s'))" % (table._table, left, sql_operator, right) else: - query = "(%s.\"%s\" %s '%s')" % (table._table, left, op, right) + query = "(%s.\"%s\" %s '%s')" % (table._table, left, sql_operator, right) add_null = False - if like: + if need_wildcard: if isinstance(right, str): str_utf8 = right elif isinstance(right, unicode): |
