[IMP] web: search view for "Schedule activity" dialog

Before this commit, click on "Schedule activity" in the activity view
would open a dialog in which the search view is the default one on the
current activity view model.

With this commit, we make the dialog use the same search view as the
activity view.

Done to help with the task 2502339

closes odoo/odoo#73697

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2021-07-14 14:05:39 +00:00
parent 57ba855b66
commit 5225b75a93
4 changed files with 74 additions and 4 deletions
@@ -32,6 +32,7 @@ var ActivityController = BasicController.extend({
init: function (parent, model, renderer, params) {
this._super.apply(this, arguments);
this.title = params.title;
this.searchViewId = params.searchViewId;
},
//--------------------------------------------------------------------------
@@ -59,6 +60,7 @@ var ActivityController = BasicController.extend({
var state = this.model.get(this.handle);
new ViewDialogs.SelectCreateDialog(this, {
res_model: state.model,
searchViewId: this.searchViewId,
domain: this.model.originalDomain,
title: _.str.sprintf(_t("Search: %s"), this.title),
no_create: !this.activeActions.create,
@@ -26,9 +26,11 @@ const ActivityView = BasicView.extend({
/**
* @override
*/
init: function () {
init: function (viewInfo, params) {
this._super.apply(this, arguments);
const { search_view_id } = params.action || {};
this.controllerParams.searchViewId = search_view_id ? search_view_id[0] : false;
this.loadParams.type = 'list';
// limit makes no sense in this view as we display all records having activities
this.loadParams.limit = false;
+67 -2
View File
@@ -7,9 +7,8 @@ import domUtils from 'web.dom';
import { legacyExtraNextTick, patchWithCleanup } from "@web/../tests/helpers/utils";
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
import { patch, unpatch } from 'web.utils';
import { registry } from "@web/core/registry";
import { session } from '@web/session';
import { click } from "@web/../tests/helpers/utils";
let serverData;
@@ -621,4 +620,70 @@ QUnit.test("Activity view: on_destroy_callback doesn't crash", async function (a
activity.destroy();
});
QUnit.test("Schedule activity dialog uses the same search view as activity view", async function (assert) {
assert.expect(8);
serverData.models.task.records = [];
serverData.views = {
"task,false,activity": `
<activity string="Task">
<templates>
<div t-name="activity-box">
<field name="foo"/>
</div>
</templates>
</activity>
`,
"task,false,list": `<list><field name="foo"/></list>`,
"task,false,search": `<search/>`,
'task,1,search': `<search/>`,
};
function mockRPC(route, args) {
if (args.method === "load_views") {
assert.step(JSON.stringify(args.kwargs.views));
}
}
const webClient = await createWebClient({ serverData, mockRPC, legacyParams: {withLegacyMockServer: true} });
// open an activity view (with default search arch)
await doAction(webClient, {
name: 'Dashboard',
res_model: 'task',
type: 'ir.actions.act_window',
views: [[false, 'activity']],
});
assert.verifySteps([
'[[false,"activity"],[false,"search"]]',
])
// click on "Schedule activity"
await click(webClient.el.querySelector(".o_activity_view .o_record_selector"));
assert.verifySteps([
'[[false,"list"],[false,"search"]]',
])
// open an activity view (with search arch 1)
await doAction(webClient, {
name: 'Dashboard',
res_model: 'task',
type: 'ir.actions.act_window',
views: [[false, 'activity']],
search_view_id: [1,"search"],
});
assert.verifySteps([
'[[false,"activity"],[1,"search"]]',
])
// click on "Schedule activity"
await click(webClient.el.querySelector(".o_activity_view .o_record_selector"));
assert.verifySteps([
'[[false,"list"],[1,"search"]]',
])
});
});
@@ -335,7 +335,8 @@ var SelectCreateDialog = ViewDialog.extend({
var _super = this._super.bind(this);
var viewRefID = this.viewType === 'kanban' ?
(this.options.kanban_view_ref && JSON.parse(this.options.kanban_view_ref) || false) : false;
return this.loadViews(this.res_model, this.context, [[viewRefID, this.viewType], [false, 'search']], {load_filters: true})
const searchviewId = this.options.searchViewId || false;
return this.loadViews(this.res_model, this.context, [[viewRefID, this.viewType], [searchviewId, 'search']], {load_filters: true})
.then(this.setup.bind(this))
.then(function (fragment) {
self.opened().then(function () {