[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
This commit is contained in:
parent
61f361bfee
commit
2f10bc4071
|
@ -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; }
|
||||
|
|
Loading…
Reference in New Issue