-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_program.js
More file actions
86 lines (78 loc) · 2.59 KB
/
create_program.js
File metadata and controls
86 lines (78 loc) · 2.59 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
/** @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 {user} from "@web/core/user";
import {useService} from "@web/core/utils/hooks";
/**
* Client action to close modal and then open program form.
* This ensures proper sequencing with async/await.
*/
async function openProgramCloseModal(env, action) {
const actionService = env.services.action;
const programId = action.params?.program_id;
await actionService.doAction(
{type: "ir.actions.act_window_close"},
{clearBreadcrumbs: true}
);
if (programId) {
await actionService.doAction({
type: "ir.actions.act_window",
name: "Program",
res_model: "spp.program",
res_id: programId,
views: [[false, "form"]],
target: "current",
});
}
}
registry.category("actions").add("open_program_close_modal", openProgramCloseModal);
patch(ListController.prototype, {
setup() {
super.setup();
this.actionService = useService("action");
onWillStart(async () => {
if (this.model.root.resModel !== "spp.program") {
return;
}
const is_admin = await user.hasGroup("spp_security.group_spp_admin");
const is_program_manager = await user.hasGroup(
"spp_programs.group_programs_manager"
);
if (is_admin || is_program_manager) {
this.customListCreateButton = {
label: "Create Program",
title: "Create a New Program",
className: "o_list_button_add_program",
};
}
});
},
/**
* Opens the Create Program wizard when the custom button is clicked.
*/
async onCustomListCreate() {
if (this.model.root.resModel === "spp.program") {
await this.actionService.doAction(
"spp_programs.action_create_program_wizard",
{
onClose: async () => {
await this.model.root.load();
},
}
);
return;
}
return super.onCustomListCreate(...arguments);
},
});
patch(FormController.prototype, {
setup() {
super.setup();
if (this.props.resModel === "spp.program") {
this.hideFormCreateButton = true;
}
},
});