diff --git a/spp_programs/static/src/js/create_program.js b/spp_programs/static/src/js/create_program.js index 77f1e9c..9ac04f9 100644 --- a/spp_programs/static/src/js/create_program.js +++ b/spp_programs/static/src/js/create_program.js @@ -3,9 +3,41 @@ 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; + const programName = action.params?.name || "Program"; + const viewId = action.params?.view_id || false; + + // First close the modal + await actionService.doAction( + {type: "ir.actions.act_window_close"}, + {clearBreadcrumbs: true} + ); + + // Then open the program form + if (programId) { + await actionService.doAction({ + type: "ir.actions.act_window", + name: programName, + res_model: "spp.program", + res_id: programId, + views: [[viewId, "form"]], + target: "current", + }); + } +} + +registry.category("actions").add("open_program_close_modal", openProgramCloseModal); + patch(ListController.prototype, { setup() { super.setup(); diff --git a/spp_programs/tests/test_create_program_wiz.py b/spp_programs/tests/test_create_program_wiz.py index 70527bb..6562cb1 100644 --- a/spp_programs/tests/test_create_program_wiz.py +++ b/spp_programs/tests/test_create_program_wiz.py @@ -34,7 +34,7 @@ def setUp(self): } ) - self.program = self._program_create_wiz.create_program() + self._program_action = self._program_create_wiz.create_program() # self.cycle_manager_default = ( # self._program_create_wiz.create_cycle_manager_default(self.program.id) # ) @@ -69,19 +69,19 @@ def test_02_create_program(self): ) res = new_wiz.create_program() self.assertEqual(type(res), dict, "Action should be in json format!") - for key in ("type", "res_model", "res_id"): + for key in ("type", "tag", "params"): self.assertIn(key, res.keys(), f"Key `{key}` is missing!") self.assertEqual( res["type"], - "ir.actions.act_window", + "ir.actions.client", "Action for program should be returned!", ) - self.assertEqual(res["res_model"], "spp.program", "Action for program should be return!") - self.assertTrue(res["res_id"], "New record for program should be existed!") + self.assertEqual(res["tag"], "open_program_close_modal", "Client action tag should match!") + self.assertTrue(res["params"]["program_id"], "New record for program should be existed!") def test_03_get_eligibility_manager(self): self._program_create_wiz.eligibility_type = "default_eligibility" - res = self._program_create_wiz._get_eligibility_manager(self.program["res_id"]) + res = self._program_create_wiz._get_eligibility_manager(self._program_action["params"]["program_id"]) self.assertIn("eligibility_managers", res) @@ -115,7 +115,7 @@ def test_06_create_program(self): "entitlement_item_ids": [Command.create({"product_id": self.product.id, "quantity": 1})], } ) - program = new_wiz.create_program() + action = new_wiz.create_program() - self.assertEqual(program["res_model"], "spp.program") - self.assertIsNotNone(program) + self.assertEqual(action["type"], "ir.actions.client") + self.assertTrue(action["params"]["program_id"]) diff --git a/spp_programs/tests/test_spp_cycle_compliance.py b/spp_programs/tests/test_spp_cycle_compliance.py index ba9f027..6a8ff8d 100644 --- a/spp_programs/tests/test_spp_cycle_compliance.py +++ b/spp_programs/tests/test_spp_cycle_compliance.py @@ -21,7 +21,7 @@ def setUpClass(cls): } ) action = cls._test.create_program() - cls.program = cls.env["spp.program"].browse(action["res_id"]) + cls.program = cls.env["spp.program"].browse(action["params"]["program_id"]) @classmethod def _create_individual(self, vals): diff --git a/spp_programs/tests/test_spp_program_create_wizard_compliance.py b/spp_programs/tests/test_spp_program_create_wizard_compliance.py index d49ae24..cbf28cd 100644 --- a/spp_programs/tests/test_spp_program_create_wizard_compliance.py +++ b/spp_programs/tests/test_spp_program_create_wizard_compliance.py @@ -12,7 +12,7 @@ def test_01_create_program_without_compliance_manager(self): wizard = self.program_create_wizard({}) wizard._check_compliance_manager_info() action = wizard.create_program() - program = self.env["spp.program"].browse(action["res_id"]) + program = self.env["spp.program"].browse(action["params"]["program_id"]) self.assertFalse( bool(program.compliance_manager_ids), "Should not create compliance manager for new program!", @@ -38,7 +38,7 @@ def test_03_create_program_default_compliance_manager(self): } ) action = wizard.create_program() - program = self.env["spp.program"].browse(action["res_id"]) + program = self.env["spp.program"].browse(action["params"]["program_id"]) self.assertTrue( bool(program.compliance_manager_ids), "Should create compliance manager for new program!", diff --git a/spp_programs/views/managers/eligibility_manager_view.xml b/spp_programs/views/managers/eligibility_manager_view.xml index 61f8897..4fd39a5 100644 --- a/spp_programs/views/managers/eligibility_manager_view.xml +++ b/spp_programs/views/managers/eligibility_manager_view.xml @@ -67,7 +67,7 @@ Part of OpenSPP. See LICENSE file for full copyright and licensing details. - + - +