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 <https://openfifth.co.uk/>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2025-10-23 12:12:10 +01:00
parent dcc946473b
commit 018e65c811
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
2 changed files with 31 additions and 0 deletions

View File

@ -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,

View File

@ -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: