[IMP] add view's context to m2o completion name_search

bzr revid: xmo@openerp.com-20130225165236-386r8438h4vz6fav
This commit is contained in:
Xavier Morel 2013-02-25 17:52:36 +01:00
parent ece114024f
commit 6803c0048f
2 changed files with 11 additions and 7 deletions

View 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(

View 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);