[IMP] add view's context to m2o completion name_search
authorXavier Morel <xmo@openerp.com>
Mon, 25 Feb 2013 16:52:36 +0000 (17:52 +0100)
committerXavier Morel <xmo@openerp.com>
Mon, 25 Feb 2013 16:52:36 +0000 (17:52 +0100)
bzr revid: xmo@openerp.com-20130225165236-386r8438h4vz6fav

addons/web/static/src/js/search.js
addons/web/static/test/search.js

index 44b8c61..36f7664 100644 (file)
@@ -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(
index 83e6ff1..904af63 100644 (file)
@@ -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);