summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-06-01 15:21:03 +0200
committerChristophe Matthieu <chm@odoo.com>2017-06-13 15:47:47 +0200
commit83115b2a108f3444468c6883f9df3b7540f706bb (patch)
treebf57954df9099242e137c27bb6e56b16139815d8 /addons/web/static
parent708c1c2915563a40a1e4c736b4fd11ffd89280f8 (diff)
[FIX] web: SelectCreateDialog uses the domain of the view when searching
before this fix: the domain is used when opening the dialog but it is not used if the user update the filter or the group_by.
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/views/view_dialogs.js4
-rw-r--r--addons/web/static/tests/views/view_dialogs_tests.js79
2 files changed, 80 insertions, 3 deletions
diff --git a/addons/web/static/src/js/views/view_dialogs.js b/addons/web/static/src/js/views/view_dialogs.js
index 4035ea6e63e..d38400c2e84 100644
--- a/addons/web/static/src/js/views/view_dialogs.js
+++ b/addons/web/static/src/js/views/view_dialogs.js
@@ -327,7 +327,6 @@ var SelectCreateDialog = ViewDialog.extend({
var searchview = new SearchView(this, this.dataset, fields_views.search, options);
searchview.prependTo($header).done(function () {
var d = searchview.build_search_data();
- d.domains = d.domains.concat([self.domain]);
if (self.initial_ids) {
d.domains.push([["id", "in", self.initial_ids]]);
self.initial_ids = undefined;
@@ -388,8 +387,9 @@ var SelectCreateDialog = ViewDialog.extend({
contexts: [this.context].concat(contexts),
group_by_seq: groupbys || []
});
+ var context = _.omit(results.context, function (value, key) { return key.indexOf('search_default_') === 0; });
return {
- context: results.context,
+ context: context,
domain: results.domain,
groupBy: results.group_by,
};
diff --git a/addons/web/static/tests/views/view_dialogs_tests.js b/addons/web/static/tests/views/view_dialogs_tests.js
index 963b3c1552e..8c46d8fff46 100644
--- a/addons/web/static/tests/views/view_dialogs_tests.js
+++ b/addons/web/static/tests/views/view_dialogs_tests.js
@@ -10,10 +10,14 @@ QUnit.module('Views', {
this.data = {
partner: {
fields: {
+ display_name: { string: "Displayed name", type: "char" },
foo: {string: "Foo", type: 'char'},
+ bar: {string: "Bar", type: "boolean"},
},
records: [
- {id: 1, foo: 'blip',},
+ {id: 1, foo: 'blip', display_name: 'blipblip', bar: true},
+ {id: 2, foo: 'ta tata ta ta', display_name: 'macgyver', bar: false},
+ {id: 3, foo: 'piou piou', display_name: "Jack O'Neill", bar: true},
],
},
};
@@ -63,6 +67,79 @@ QUnit.module('Views', {
dialog.destroy();
});
+ QUnit.test('SelectCreateDialog use domain, group_by and search default', function (assert) {
+ assert.expect(3);
+
+ var search = 0;
+ var parent = createParent({
+ data: this.data,
+ archs: {
+ 'partner,false,list':
+ '<tree string="Partner">' +
+ '<field name="display_name"/>' +
+ '<field name="foo"/>' +
+ '</tree>',
+ 'partner,false,search':
+ '<search>' +
+ '<field name="foo" filter_domain="[(\'display_name\',\'ilike\',self), (\'foo\',\'ilike\',self)]"/>' +
+ '<group expand="0" string="Group By">' +
+ '<filter name="groupby_bar" context="{\'group_by\' : \'bar\'}"/>' +
+ '</group>' +
+ '</search>',
+ },
+ mockRPC: function (route, args) {
+ search++;
+ if (search === 1 && args.method === 'read_group') {
+ assert.deepEqual(args.kwargs, {
+ context: {group_by: "bar"},
+ domain: [["display_name","like","a"], ["display_name","ilike","piou"], ["foo","ilike","piou"]],
+ fields:["display_name","foo","bar"],
+ groupby:["bar"],
+ lazy: true
+ }, "should search with the complete domain (domain + search), and group by 'bar'");
+ }
+ if (search === 2 && route === '/web/dataset/search_read') {
+ assert.deepEqual(args, {
+ context: {},
+ domain: [["display_name","like","a"], ["display_name","ilike","piou"], ["foo","ilike","piou"]],
+ fields:["display_name","foo"],
+ model: "partner",
+ limit: 80,
+ sort: ""
+ }, "should search with the complete domain (domain + search)");
+ }
+ if (search === 3 && route === '/web/dataset/search_read') {
+ assert.deepEqual(args, {
+ context: {},
+ domain: [["display_name","like","a"]],
+ fields:["display_name","foo"],
+ model: "partner",
+ limit: 80,
+ sort: ""
+ }, "should search with the domain");
+ }
+
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ var dialog = new dialogs.SelectCreateDialog(parent, {
+ no_create: true,
+ readonly: true,
+ res_model: 'partner',
+ domain: [['display_name', 'like', 'a']],
+ context: {
+ search_default_groupby_bar: true,
+ search_default_foo: 'piou',
+ },
+ }).open();
+
+ dialog.$('.o_searchview_facet:contains(groupby_bar) .o_facet_remove').click();
+ dialog.$('.o_searchview_facet .o_facet_remove').click();
+
+ dialog.destroy();
+ });
+
});
}); \ No newline at end of file