From 27c16a772107de1dfd6d0aa41b24bebf47e9cf96 Mon Sep 17 00:00:00 2001 From: Xavier ALT Date: Fri, 25 May 2012 15:14:16 +0200 Subject: [PATCH] [FIX] OPW 574218: many2one: do not prefilter records when user click on 'Search More' with empty text - Normally when user click on 'Search More' on many2one fields, relation object records are prefiltered based on the text user entered in the many2one field. But if user do not enter any text before click on 'Search More', system will call name_search() with an empty search criteria - and this could be quite expensive depending on the size of the dataset!. (this of name_search() on more that 10.000 products...) We now do not prefilter records if search value is empty (standard domain filtering still apply). bzr revid: xal@openerp.com-20120525131416-ie958wu0cihjslgc --- addons/web/static/src/js/view_form.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 123af3a6050..948c34a20b5 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2056,11 +2056,20 @@ openerp.web.form.FieldMany2One = openerp.web.form.Field.extend({ if (values.length > self.limit) { values = values.slice(0, self.limit); values.push({label: _t("   Search More..."), action: function() { - dataset.name_search(search_val, self.build_domain(), 'ilike' - , false, function(data) { + if (search_val.length == 0) { + // search optimisation - in case user didn't enter any text we + // do not need to prefilter records; for big datasets (ex: more + // that 10.000 records) calling name_search() could be very very + // expensive! self._change_int_value(null); - self._search_create_popup("search", data); - }); + self._search_create_popup("search", undefined); + } else { + dataset.name_search(search_val, self.build_domain(), 'ilike' + , false, function(data) { + self._change_int_value(null); + self._search_create_popup("search", data); + }); + } }}); } // quick create