From 65c0649f7072518360847be04842fa2719ff514a Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 21 Sep 2011 13:23:28 +0200 Subject: [PATCH 1/3] [IMP] base, res_currency: added search view bzr revid: qdp-launchpad@openerp.com-20110921112328-o2htuetcopy4jqj5 --- openerp/addons/base/res/res_currency_view.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 @@ + + res.currency.search + res.currency + search + + + + + + + + res.currency.tree res.currency @@ -62,6 +74,7 @@ res.currency form tree,form + From 60d9065ff1d0115be69440cdc44543ddceab81a9 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 21 Sep 2011 18:08:25 +0200 Subject: [PATCH 2/3] [fix] problem with context and default_get bzr revid: nicolas.vanhoren@openerp.com-20110921160825-6o1ggc0tar1i18j6 --- addons/web/static/src/js/view_form.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index fea6ba21e01..2c730d0b5af 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1007,19 +1007,18 @@ openerp.web.form.Field = openerp.web.form.Widget.extend(/** @lends openerp.web.f * the fields'context with the action's context. */ build_context: function() { - // I previously belevied contexts should be herrited, but now I doubt it - //var a_context = this.view.dataset.get_context() || {}; var f_context = this.field.context || null; // maybe the default_get should only be used when we do a default_get? - var v_context1 = this.node.attrs.default_get || {}; - var v_context2 = this.node.attrs.context || {}; - var v_context = new openerp.web.CompoundContext(v_context1, v_context2); - if (v_context1.__ref || v_context2.__ref || true) { //TODO niv: remove || true + var v_contexts = _.compact([this.node.attrs.default_get || null, + this.node.attrs.context || null]); + var v_context = new openerp.web.CompoundContext(); + _.each(v_contexts, function(x) {v_context.add(x);}); + if (_.detect(v_contexts, function(x) {return !!x.__ref;})) { var fields_values = this._build_view_fields_values(); v_context.set_eval_context(fields_values); } // if there is a context on the node, overrides the model's context - var ctx = f_context || v_context; + var ctx = v_contexts.length > 0 ? v_context : f_context; return ctx; }, build_domain: function() { From 886b7407dedc7256492c78d1e7873a0e6efed3be Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 22 Sep 2011 00:42:08 +0200 Subject: [PATCH 3/3] [FIX] osv.expression: fix =like/=ilike operators, broken by r.3631 Revision 3631 = vmt@openerp.com-20110920124252-l5snbvb7ywfogw1o bzr revid: odo@openerp.com-20110921224208-mji81to3g4kpmkuq --- .../addons/base/test/test_osv_expression.yml | 20 ++++++------ openerp/osv/expression.py | 31 +++++++++---------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/openerp/addons/base/test/test_osv_expression.yml b/openerp/addons/base/test/test_osv_expression.yml index 169347cc532..b0c46ce7f13 100644 --- a/openerp/addons/base/test/test_osv_expression.yml +++ b/openerp/addons/base/test/test_osv_expression.yml @@ -188,18 +188,18 @@ norm_domain = ['&','&','&'] + domain assert norm_domain == expression.normalize(domain), "Non-normalized domains should be properly normalized" - - 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 c6db1e9f412..96f5a5cf34f 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -425,10 +425,11 @@ 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 - + query1 = '( SELECT res_id' \ ' FROM ir_translation' \ ' WHERE name = %s' \ @@ -436,19 +437,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)) - query1 += ' AND value ' + operator + ' ' +" (" + instr + ")" \ + query1 += ' AND value ' + sql_operator + ' ' +" (" + instr + ")" \ ') UNION (' \ ' SELECT id' \ ' FROM "' + working_table._table + '"' \ - ' WHERE "' + left + '" ' + operator + ' ' +" (" + instr + "))" + ' WHERE "' + left + '" ' + sql_operator + ' ' +" (" + instr + "))" else: - query1 += ' AND value ' + operator + instr + \ + query1 += ' AND value ' + sql_operator + instr + \ ') UNION (' \ ' SELECT id' \ ' FROM "' + working_table._table + '"' \ - ' WHERE "' + left + '" ' + operator + instr + ")" + ' WHERE "' + left + '" ' + sql_operator + instr + ")" query2 = [working_table._name + ',' + left, context.get('lang', False) or 'en_US', @@ -521,18 +522,16 @@ 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) + need_wildcard = operator in ('like', 'ilike', 'not like', 'not ilike') + sql_operator = {'=like':'like','=ilike':'ilike'}.get(operator,operator) if left in table._columns: - format = like and '%s' or table._columns[left]._symbol_set[0] - query = '(%s."%s" %s %s)' % (table._table, left, op, format) + format = need_wildcard and '%s' or table._columns[left]._symbol_set[0] + query = '(%s."%s" %s %s)' % (table._table, left, sql_operator, format) 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):