From 2f10bc40713f3cffddf6d7ad11182bcf08b35642 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 24 Jul 2012 13:56:59 +0200 Subject: [PATCH] [IMP] validation of search_default values for m2o fields Just because the search_default is an array does not mean it's a name_get apparently: there are many cases of a single id wrapped in an array (``[id]``). So ensure that the search_default is an array *of length 2 whose second element is a string* before considering it a name_get and using it as-is (without resolving the label via an explicit name_get). Also, error out for any m2o search_default which is an array of length > 1 (unless the second element is a string as per description above). bzr revid: xmo@openerp.com-20120724115659-l0n0gjr91bcop13z --- addons/web/static/src/js/search.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 504510ef133..8de2562a798 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -1475,7 +1475,17 @@ instance.web.search.ManyToOneField = instance.web.search.CharField.extend({ facet_for: function (value) { var self = this; if (value instanceof Array) { - return $.when(facet_from(this, value)); + if (value.length === 2 && _.isString(value[1])) { + return $.when(facet_from(this, value)); + } + if (value.length > 1) { + // more than one search_default m2o id? Should we OR them? + throw new Error( + _("M2O search fields do not currently handle multiple default values")); + } + // there are many cases of {search_default_$m2ofield: [id]}, need + // to handle this as if it were a single value. + value = value[0]; } return this.model.call('name_get', [value], {}).pipe(function (names) { if (_(names).isEmpty()) { return null; }