From 6803c0048f6d7447ca4ba84e1a9e52f2aedbdb33 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 25 Feb 2013 17:52:36 +0100 Subject: [PATCH] [IMP] add view's context to m2o completion name_search bzr revid: xmo@openerp.com-20130225165236-386r8438h4vz6fav --- addons/web/static/src/js/search.js | 7 ++++--- addons/web/static/test/search.js | 11 +++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 44b8c61b9a6..36f766407b7 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -1473,14 +1473,15 @@ instance.web.search.ManyToOneField = instance.web.search.CharField.extend({ }, complete: function (needle) { var self = this; - // TODO: context // FIXME: "concurrent" searches (multiple requests, mis-ordered responses) + var context = instance.web.pyeval.eval( + 'contexts', [this.view.dataset.get_context()]); return this.model.call('name_search', [], { name: needle, args: instance.web.pyeval.eval( - 'domains', this.attrs.domain ? [this.attrs.domain] : []), + 'domains', this.attrs.domain ? [this.attrs.domain] : [], context), limit: 8, - context: {} + context: context }).then(function (results) { if (_.isEmpty(results)) { return null; } return [{label: self.attrs.string}].concat( diff --git a/addons/web/static/test/search.js b/addons/web/static/test/search.js index 83e6ff1c178..904af63f590 100644 --- a/addons/web/static/test/search.js +++ b/addons/web/static/test/search.js @@ -557,7 +557,7 @@ openerp.testing.section('completions', { return [[42, "choice 1"], [43, "choice @"]]; }); - var view = {inputs: []}; + var view = {inputs: [], dataset: {get_context: function () {}}}; var f = new instance.web.search.ManyToOneField( {attrs: {string: 'Dummy'}}, {relation: 'dummy.model'}, view); return f.complete("bob") @@ -586,7 +586,7 @@ openerp.testing.section('completions', { strictEqual(kwargs.name, 'bob'); return []; }); - var view = {inputs: []}; + var view = {inputs: [], dataset: {get_context: function () {}}}; var f = new instance.web.search.ManyToOneField( {attrs: {string: 'Dummy'}}, {relation: 'dummy.model'}, view); return f.complete("bob") @@ -601,11 +601,14 @@ openerp.testing.section('completions', { name: 'bob', limit: 8, args: [['foo', '=', 'bar']], - context: {}, + context: {flag: 1}, }, "should use filtering domain"); return [[42, "Match"]]; }); - var view = {inputs: []}; + var view = { + inputs: [], + dataset: {get_context: function () { return {flag: 1}; }} + }; var f = new instance.web.search.ManyToOneField( {attrs: {string: 'Dummy', domain: '[["foo", "=", "bar"]]'}}, {relation: 'dummy.model'}, view);