@@ -, +, @@ --- Koha/REST/V1/Acquisitions/Orders.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/Koha/REST/V1/Acquisitions/Orders.pm +++ a/Koha/REST/V1/Acquisitions/Orders.pm @@ -183,7 +183,9 @@ sub update { =head3 delete -Controller function that handles deleting a Koha::Patron object +Controller function that handles deleting a Koha::Acquisition::Order object + +Note that we only allow deletion when the status is cancelled. =cut @@ -197,6 +199,12 @@ sub delete { status => 404, openapi => { error => 'Order not found' } ); + } elsif ( ( $order->orderstatus && $order->orderstatus ne 'cancelled' ) || !$order->datecancellationprinted ) { + # Koha may (historically) have inconsistent order data here (e.g. cancelled without date) + return $c->render( + status => 403, + openapi => { error => 'Order status must be cancelled' } + ); } return try { --