Skip to content

Commit 6fe3cc1

Browse files
committed
fix(spp_change_request_v2): reliably close wizard modal after CR creation
Use ir.actions.client with async/await pattern to close the wizard modal before navigating to the CR detail form. Same approach as spp_programs wizard — prevents the modal from staying open on slow connections.
1 parent 54337dd commit 6fe3cc1

2 files changed

Lines changed: 53 additions & 20 deletions

File tree

spp_change_request_v2/static/src/js/create_change_request.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,39 @@ import {FormController} from "@web/views/form/form_controller";
44
import {ListController} from "@web/views/list/list_controller";
55
import {onWillStart} from "@odoo/owl";
66
import {patch} from "@web/core/utils/patch";
7+
import {registry} from "@web/core/registry";
78
import {useService} from "@web/core/utils/hooks";
89
import {user} from "@web/core/user";
910

11+
/**
12+
* Client action to close wizard modal and then open CR detail form.
13+
* Uses async/await to ensure the modal is fully closed before navigating.
14+
*/
15+
async function openCRCloseModal(env, action) {
16+
const actionService = env.services.action;
17+
const params = action.params || {};
18+
19+
await actionService.doAction(
20+
{type: "ir.actions.act_window_close"},
21+
{clearBreadcrumbs: true}
22+
);
23+
24+
if (params.res_id) {
25+
await actionService.doAction({
26+
type: "ir.actions.act_window",
27+
name: params.name || "Change Request Details",
28+
res_model: params.res_model,
29+
res_id: params.res_id,
30+
view_mode: "form",
31+
views: [[params.view_id || false, "form"]],
32+
target: "current",
33+
context: params.context || {},
34+
});
35+
}
36+
}
37+
38+
registry.category("actions").add("open_cr_close_modal", openCRCloseModal);
39+
1040
patch(ListController.prototype, {
1141
setup() {
1242
super.setup();

spp_change_request_v2/wizards/create_wizard.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -232,35 +232,38 @@ def action_create_draft(self):
232232
}
233233
)
234234

235-
# Open the detail form directly for editing
235+
# Close wizard modal and open detail form using client action
236+
# The client action ensures the modal is fully closed before navigating
236237
detail = cr.get_detail()
237238
if detail:
238239
view_id = self.request_type_id.get_detail_form_view_id()
239240
return {
240-
"type": "ir.actions.act_window",
241-
"name": "Change Request Details",
242-
"res_model": cr.detail_res_model,
243-
"res_id": detail.id,
244-
"view_mode": "form",
245-
"view_id": view_id,
246-
"target": "current",
247-
"context": {
248-
"create": False,
249-
"delete": False,
250-
"form_view_initial_mode": "edit",
241+
"type": "ir.actions.client",
242+
"tag": "open_cr_close_modal",
243+
"params": {
244+
"name": _("Change Request Details"),
245+
"res_model": cr.detail_res_model,
246+
"res_id": detail.id,
247+
"view_id": view_id,
248+
"context": {
249+
"create": False,
250+
"delete": False,
251+
"form_view_initial_mode": "edit",
252+
},
251253
},
252254
}
253255

254256
# Fallback: open CR form if no detail model configured
255257
return {
256-
"type": "ir.actions.act_window",
257-
"name": "Change Request",
258-
"res_model": "spp.change.request",
259-
"res_id": cr.id,
260-
"view_mode": "form",
261-
"target": "current",
262-
"context": {
263-
"form_view_initial_mode": "edit",
258+
"type": "ir.actions.client",
259+
"tag": "open_cr_close_modal",
260+
"params": {
261+
"name": _("Change Request"),
262+
"res_model": "spp.change.request",
263+
"res_id": cr.id,
264+
"context": {
265+
"form_view_initial_mode": "edit",
266+
},
264267
},
265268
}
266269

0 commit comments

Comments
 (0)