From 156e1e446c26fde25f1f1e1a2ce6c984e0f0498b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 23 Oct 2025 12:12:10 +0100 Subject: [PATCH 11/16] Bug 23415: Add REST API support for fine override on renewal This commit adds support for the AllowFineOverrideRenewing functionality to the REST API renewal endpoints using the standard x-koha-override pattern. Changes: 1. Added x-koha-override header parameter to both renewal endpoints: - POST /checkouts/{checkout_id}/renewal - POST /checkouts/{checkout_id}/renewals 2. Updated Koha::REST::V1::Checkouts::renew() to: - Check for 'debt_limit' in the overrides stash - Check AllowFineOverrideRenewing preference when override is requested - Allow renewal override only when both: * x-koha-override header contains 'debt_limit' AND * AllowFineOverrideRenewing preference is enabled - Follows the established x-koha-override pattern used by other endpoints 3. Updated OpenAPI specification (swagger) to document the new header using the standard pattern with enum values Usage: curl -X POST /api/v1/checkouts/123/renewal \ -H "x-koha-override: debt_limit" The override only works for too_much_owing errors and requires the AllowFineOverrideRenewing system preference to be enabled. This implementation follows the same pattern as holds and other endpoints that support overrides, maintaining consistency across the REST API. Sponsored-by: OpenFifth Signed-off-by: Andrew Fuerste Henry Signed-off-by: Martin Renvoize --- Koha/REST/V1/Checkouts.pm | 11 +++++++++++ api/v1/swagger/paths/checkouts.yaml | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm index 21b7303a90..ab99808d49 100644 --- a/Koha/REST/V1/Checkouts.pm +++ b/Koha/REST/V1/Checkouts.pm @@ -375,6 +375,17 @@ sub renew { return try { my ( $can_renew, $error ) = CanBookBeRenewed( $checkout->patron, $checkout ); + # Check if error is due to excessive fines and override is requested + if ( !$can_renew && ( $error eq 'too_much_owing' or $error eq 'auto_too_much_owing' ) ) { + my $overrides = $c->stash('koha.overrides'); + if ( $overrides->{debt_limit} && C4::Context->preference("AllowFineOverrideRenewing") ) { + + # Override is allowed, proceed with renewal + $can_renew = 1; + $error = undef; + } + } + if ( !$can_renew ) { return $c->render( status => 403, diff --git a/api/v1/swagger/paths/checkouts.yaml b/api/v1/swagger/paths/checkouts.yaml index 2433916072..4279bd080a 100644 --- a/api/v1/swagger/paths/checkouts.yaml +++ b/api/v1/swagger/paths/checkouts.yaml @@ -203,6 +203,16 @@ parameters: - $ref: "../swagger.yaml#/parameters/checkout_id_pp" - $ref: "../swagger.yaml#/parameters/seen_pp" + - name: x-koha-override + in: header + required: false + description: Overrides list sent as a request header + type: array + items: + type: string + enum: + - debt_limit + collectionFormat: csv produces: - application/json responses: @@ -246,6 +256,16 @@ parameters: - $ref: "../swagger.yaml#/parameters/checkout_id_pp" - $ref: "../swagger.yaml#/parameters/seen_pp" + - name: x-koha-override + in: header + required: false + description: Overrides list sent as a request header + type: array + items: + type: string + enum: + - debt_limit + collectionFormat: csv produces: - application/json responses: -- 2.34.1