From 18220e6adb9694d1c033f0b70f3679d276bb319d Mon Sep 17 00:00:00 2001 From: emjay0921 Date: Mon, 23 Mar 2026 11:36:01 +0800 Subject: [PATCH 1/4] fix(spp_change_request_v2): fix batch approval wizard line deletion Replace act_window bindings with server actions that create the wizard record before opening the form, so One2many line operations work without "Please save your changes first" errors. --- .../tests/test_ux_wizards.py | 27 ++++--- .../views/batch_approval_wizard_views.xml | 49 ++++++------ .../wizards/batch_approval_wizard.py | 79 +++++++++++-------- 3 files changed, 81 insertions(+), 74 deletions(-) diff --git a/spp_change_request_v2/tests/test_ux_wizards.py b/spp_change_request_v2/tests/test_ux_wizards.py index ea8cca2c..072d533d 100644 --- a/spp_change_request_v2/tests/test_ux_wizards.py +++ b/spp_change_request_v2/tests/test_ux_wizards.py @@ -254,16 +254,26 @@ def setUp(self): cr.action_submit_for_approval() self.pending_crs |= cr + def _create_wizard(self, cr_ids, action_type="approve", **kwargs): + """Helper to create a batch wizard via create_from_selection.""" + result = ( + self.env["spp.cr.batch.approval.wizard"].with_context(active_ids=cr_ids).create_from_selection(action_type) + ) + wizard = self.env["spp.cr.batch.approval.wizard"].browse(result["res_id"]) + if kwargs: + wizard.write(kwargs) + return wizard + def test_batch_wizard_initialization(self): """Test batch wizard initializes with selected CRs.""" - wizard = self.env["spp.cr.batch.approval.wizard"].with_context(active_ids=self.pending_crs.ids).create({}) + wizard = self._create_wizard(self.pending_crs.ids) self.assertEqual(wizard.total_count, 3) self.assertEqual(len(wizard.line_ids), 3) def test_batch_wizard_counts(self): """Test batch wizard computes valid/invalid counts correctly.""" - wizard = self.env["spp.cr.batch.approval.wizard"].with_context(active_ids=self.pending_crs.ids).create({}) + wizard = self._create_wizard(self.pending_crs.ids) # All should be valid if user can approve self.assertEqual(wizard.total_count, wizard.valid_count + wizard.invalid_count) @@ -279,7 +289,7 @@ def test_batch_approve_requires_valid_crs(self): } ) - wizard = self.env["spp.cr.batch.approval.wizard"].with_context(active_ids=[draft_cr.id]).create({}) + wizard = self._create_wizard([draft_cr.id]) # Should have 0 valid CRs self.assertEqual(wizard.valid_count, 0) @@ -289,16 +299,7 @@ def test_batch_approve_requires_valid_crs(self): def test_batch_reject_requires_comment(self): """Test batch reject requires a reason.""" - wizard = ( - self.env["spp.cr.batch.approval.wizard"] - .with_context(active_ids=self.pending_crs.ids) - .create( - { - "action_type": "reject", - "comment": "", - } - ) - ) + wizard = self._create_wizard(self.pending_crs.ids, action_type="reject", comment="") # Should fail without comment with self.assertRaises(UserError): diff --git a/spp_change_request_v2/views/batch_approval_wizard_views.xml b/spp_change_request_v2/views/batch_approval_wizard_views.xml index a133c161..a535b84b 100644 --- a/spp_change_request_v2/views/batch_approval_wizard_views.xml +++ b/spp_change_request_v2/views/batch_approval_wizard_views.xml @@ -95,7 +95,7 @@ - + -