-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_change_request.js
More file actions
89 lines (81 loc) · 2.83 KB
/
create_change_request.js
File metadata and controls
89 lines (81 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* @odoo-module */
import {FormController} from "@web/views/form/form_controller";
import {ListController} from "@web/views/list/list_controller";
import {onWillStart} from "@odoo/owl";
import {patch} from "@web/core/utils/patch";
import {registry} from "@web/core/registry";
import {useService} from "@web/core/utils/hooks";
import {user} from "@web/core/user";
/**
* Client action to close wizard modal and then open CR detail form.
* Uses async/await to ensure the modal is fully closed before navigating.
*/
async function openCRCloseModal(env, action) {
const actionService = env.services.action;
const params = action.params || {};
await actionService.doAction(
{type: "ir.actions.act_window_close"},
{clearBreadcrumbs: true}
);
if (params.res_id) {
await actionService.doAction({
type: "ir.actions.act_window",
name: params.name || "Change Request Details",
res_model: params.res_model,
res_id: params.res_id,
view_mode: "form",
views: [[params.view_id || false, "form"]],
target: "current",
context: params.context || {},
});
}
}
registry.category("actions").add("open_cr_close_modal", openCRCloseModal);
patch(ListController.prototype, {
setup() {
super.setup();
this.actionService = useService("action");
onWillStart(async () => {
if (this.model.root.resModel !== "spp.change.request") {
return;
}
const is_admin = await user.hasGroup("spp_security.group_spp_admin");
const is_cr_user = await user.hasGroup(
"spp_change_request_v2.group_cr_user"
);
if (is_admin || is_cr_user) {
this.customListCreateButton = {
label: "New Request",
title: "Create a New Change Request",
className: "o_list_button_add_cr",
};
}
});
},
/**
* Opens the Create Change Request wizard when the custom button is clicked.
*/
async onCustomListCreate() {
if (this.model.root.resModel === "spp.change.request") {
await this.actionService.doAction(
"spp_change_request_v2.action_cr_create_wizard",
{
onClose: async () => {
await this.model.root.load();
},
}
);
return;
}
return super.onCustomListCreate(...arguments);
},
});
patch(FormController.prototype, {
setup() {
super.setup();
if (this.props.resModel === "spp.change.request") {
this.hideFormCreateButton = true;
}
// Row click handling for CR create wizard is now in cr_search_results_field.js
},
});