[FIX] OPW 574218: many2one: do not prefilter records when user click on 'Search More...
authorXavier ALT <xal@openerp.com>
Fri, 25 May 2012 13:14:16 +0000 (15:14 +0200)
committerXavier ALT <xal@openerp.com>
Fri, 25 May 2012 13:14:16 +0000 (15:14 +0200)
 - 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

index 123af3a..948c34a 100644 (file)
@@ -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("<em>   Search More...</em>"), 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