From fb911b1d435ae16dc2f4d10098d81e48e8a06bd1 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 7 Nov 2013 12:12:31 +0100 Subject: [PATCH] [FIX] don't provide autocompletion to m2o fields when a custom operator or filter_domain is provided bzr revid: xmo@openerp.com-20131107111231-nkrllqv0afqdmix6 --- addons/web/static/src/js/search.js | 3 +++ addons/web/static/test/search.js | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 5e97a708a32..23907202690 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -1535,6 +1535,9 @@ instance.web.search.ManyToOneField = instance.web.search.CharField.extend({ this.model = new instance.web.Model(this.attrs.relation); }, complete: function (needle) { + if (this.attrs.operator || this.attrs.filter_domain) { + return this._super(needle); + } var self = this; // FIXME: "concurrent" searches (multiple requests, mis-ordered responses) var context = instance.web.pyeval.eval( diff --git a/addons/web/static/test/search.js b/addons/web/static/test/search.js index eea95a3ac97..c9588c77d0e 100644 --- a/addons/web/static/test/search.js +++ b/addons/web/static/test/search.js @@ -614,6 +614,29 @@ openerp.testing.section('search.completions', { {relation: 'dummy.model'}, view); return f.complete("bob"); }); + test("M2O custom operator", {asserts: 6}, function (instance) { + var view = { inputs: [], }; + var f = new instance.web.search.ManyToOneField( + {attrs: {string: 'Dummy', operator:'ilike'}}, + {relation: 'dummy.model'}, view); + + return f.complete('bob') + .done(function (completions) { + equal(completions.length, 1, "should provide a single completion"); + var c = completions[0]; + equal(c.label, "Search Dummy for: bob", + "should propose fuzzy searching of the value"); + ok(c.facet, "should have a facet"); + + var facet = new instance.web.search.Facet(c.facet); + equal(facet.get('category'), f.attrs.string, + "completion facet should bear the field's name"); + strictEqual(facet.get('field'), f, + "completion facet should yield the field"); + deepEqual(facet.values.toJSON(), [{label: 'bob', value: 'bob'}], + "facet should have a single value using the completion item"); + }); +}); test('Integer: invalid', {asserts: 1}, function (instance) { var view = {inputs: []}; var f = new instance.web.search.IntegerField(