[FIX] @domain not handled on searchview m2o fields

Also injected view context in m2o completion name_search

lp bug: https://launchpad.net/bugs/1131853 fixed

bzr revid: xmo@openerp.com-20130225165314-78e04rewsqw86r5d
This commit is contained in:
Xavier Morel
2013-02-25 17:53:14 +01:00
2 changed files with 58 additions and 4 deletions
+5 -2
View File
@@ -1473,12 +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] : [], context),
limit: 8,
context: {}
context: context
}).then(function (results) {
if (_.isEmpty(results)) { return null; }
return [{label: self.attrs.string}].concat(
+53 -2
View File
@@ -318,6 +318,28 @@ openerp.testing.section('defaults', {
"facet value should match provided default's selection");
});
});
test("M2O default: value array", {asserts: 2}, function (instance, $s, mock) {
var view = {inputs: []}, id = 5;
var f = new instance.web.search.ManyToOneField(
{attrs: {name: 'dummy', string: 'Dummy'}},
{relation: 'dummy.model.name'},
view);
mock('dummy.model.name:name_get', function (args) {
equal(args[0], id);
return [[id, "DumDumDum"]];
});
return f.facet_for_defaults({dummy: [id]})
.done(function (facet) {
var model = facet;
if (!(model instanceof instance.web.search.Facet)) {
model = new instance.web.search.Facet(facet);
}
deepEqual(
model.values.toJSON(),
[{label: "DumDumDum", value: id}],
"should support default as a singleton");
});
});
test("M2O default: value", {asserts: 1}, function (instance, $s, mock) {
var view = {inputs: []}, id = 4;
var f = new instance.web.search.ManyToOneField(
@@ -330,6 +352,15 @@ openerp.testing.section('defaults', {
ok(!facet, "an invalid m2o default should yield a non-facet");
});
});
test("M2O default: values", {rpc: false}, function (instance) {
var view = {inputs: []};
var f = new instance.web.search.ManyToOneField(
{attrs: {name: 'dummy', string: 'Dummy'}},
{relation: 'dummy.model.name'},
view);
raises(function () { f.facet_for_defaults({dummy: [6, 7]}) },
"should not accept multiple default values");
})
});
openerp.testing.section('completions', {
dependencies: ['web.search'],
@@ -526,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")
@@ -555,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")
@@ -563,6 +594,26 @@ openerp.testing.section('completions', {
ok(!c, "no match should yield no completion");
});
});
test("M2O filtered", {asserts: 2}, function (instance, $s, mock) {
mock('dummy.model:name_search', function (args, kwargs) {
deepEqual(args, [], "should have no positional arguments");
deepEqual(kwargs, {
name: 'bob',
limit: 8,
args: [['foo', '=', 'bar']],
context: {flag: 1},
}, "should use filtering domain");
return [[42, "Match"]];
});
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);
return f.complete("bob");
});
});
openerp.testing.section('search-serialization', {
dependencies: ['web.search'],