diff --git a/document_page_approval/models/document_page_history.py b/document_page_approval/models/document_page_history.py index f8572e361ad..316852a523c 100644 --- a/document_page_approval/models/document_page_history.py +++ b/document_page_approval/models/document_page_history.py @@ -1,4 +1,5 @@ # Copyright (C) 2013 Savoir-faire Linux (). +# Copyright 2026 NuoBiT Solutions SL - Deniz Gallo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -92,7 +93,11 @@ def action_approve(self): """Set a change request as approved.""" for rec in self: if rec.state not in ["draft", "to approve"]: - self.env._("Can't approve page in '%(state)s' state.", state=rec.state) + raise UserError( + self.env._( + "Can't approve page in '%(state)s' state.", state=rec.state + ) + ) if not rec.am_i_approver: groups_str = ", ".join( g.display_name for g in rec.page_id.approver_group_ids diff --git a/document_page_approval/tests/test_document_page_approval.py b/document_page_approval/tests/test_document_page_approval.py index d645e8c3042..953422e6303 100644 --- a/document_page_approval/tests/test_document_page_approval.py +++ b/document_page_approval/tests/test_document_page_approval.py @@ -239,6 +239,24 @@ def test_action_to_approve_only_from_draft(self): with self.assertRaises(UserError): chreq.action_to_approve() + def test_action_approve_only_from_draft_or_pending(self): + """Ensure approved or cancelled requests cannot be approved""" + for state in ("approved", "cancelled"): + with self.subTest(state=state): + chreq = self.history_obj.create( + { + "page_id": self.page2.id, + "state": state, + } + ) + with self.assertRaises(UserError) as error: + chreq.with_user(self.user2).action_approve() + self.assertEqual( + error.exception.args[0], + f"Can't approve page in '{state}' state.", + ) + self.assertEqual(chreq.state, state) + def test_approval_permission_check(self): """Ensure approval is restricted to approvers""" chreq = self.history_obj.create(