From be48f51df5e1f2450eb6315786976ce28f5aaebc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 23 Oct 2025 12:12:10 +0100 Subject: [PATCH] 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. --- 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 21b7303a903..ab99808d497 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 24339160720..4279bd080a7 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.51.0