From 77ca41ca51213a08aca1c3e19b6cfb395b5dc77d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 16 Sep 2025 13:48:27 +0100 Subject: [PATCH] Bug 40817: Add REST API support for hold-account line embedding This patch extends the REST API to support embedding debits in hold responses and linking holds in debit responses: API Schema Changes: - Add debits field to hold.yaml definition for embedding account lines - Add hold field to debit.yaml definition for embedding associated holds - Update holds.yaml and patrons_holds.yaml endpoints to support debits embedding Koha::Account::Debit.pm: - Add hold() method for API embedding support - Enable bidirectional API relationships between debits and holds These changes allow API clients to: - Retrieve holds with their associated charges in a single request - Access hold information from debit/charge records - Reduce API round trips by embedding related data - Support efficient financial reporting and hold management workflows --- Koha/Account/Debit.pm | 2 ++ api/v1/swagger/definitions/debit.yaml | 10 ++++++++++ api/v1/swagger/definitions/hold.yaml | 7 +++++++ api/v1/swagger/paths/holds.yaml | 11 +++++++++++ api/v1/swagger/paths/patrons_holds.yaml | 1 + 5 files changed, 31 insertions(+) diff --git a/Koha/Account/Debit.pm b/Koha/Account/Debit.pm index b113003bdad..b8d790ebda2 100644 --- a/Koha/Account/Debit.pm +++ b/Koha/Account/Debit.pm @@ -49,6 +49,8 @@ sub to_api_mapping { branchcode => 'library_id', issue_id => 'checkout_id', old_issue_id => 'old_checkout_id', + reserve_id => 'hold_id', + old_reserve_id => 'old_hold_id', itemnumber => 'item_id', manager_id => 'user_id', note => 'internal_note', diff --git a/api/v1/swagger/definitions/debit.yaml b/api/v1/swagger/definitions/debit.yaml index 07ea7d7884d..a83247c9ea9 100644 --- a/api/v1/swagger/definitions/debit.yaml +++ b/api/v1/swagger/definitions/debit.yaml @@ -28,6 +28,16 @@ properties: - integer - "null" description: Internal identifier for the old checkout the account line is related to + hold_id: + type: + - integer + - "null" + description: Internal identifier for the hold the account line is related to + old_hold_id: + type: + - integer + - "null" + description: Internal identifier for the old hold the account line is related to date: type: string format: date-time diff --git a/api/v1/swagger/definitions/hold.yaml b/api/v1/swagger/definitions/hold.yaml index f09580f8747..a88f6103d73 100644 --- a/api/v1/swagger/definitions/hold.yaml +++ b/api/v1/swagger/definitions/hold.yaml @@ -144,6 +144,13 @@ properties: - object - "null" description: Patron for hold + debits: + type: + - array + - "null" + description: Debits (charges) linked to this hold (x-koha-embed) + items: + $ref: "./debit.yaml" _strings: type: - object diff --git a/api/v1/swagger/paths/holds.yaml b/api/v1/swagger/paths/holds.yaml index 388a446ab9d..112948bd42a 100644 --- a/api/v1/swagger/paths/holds.yaml +++ b/api/v1/swagger/paths/holds.yaml @@ -108,6 +108,7 @@ - pickup_library - item - patron + - debits collectionFormat: csv produces: - application/json @@ -231,6 +232,16 @@ - hold_limit - restricted collectionFormat: csv + - name: x-koha-embed + in: header + required: false + description: Embed list sent as a request header + type: array + items: + type: string + enum: + - debits + collectionFormat: csv consumes: - application/json produces: diff --git a/api/v1/swagger/paths/patrons_holds.yaml b/api/v1/swagger/paths/patrons_holds.yaml index b8c28f30d83..9fb99b4c885 100644 --- a/api/v1/swagger/paths/patrons_holds.yaml +++ b/api/v1/swagger/paths/patrons_holds.yaml @@ -34,6 +34,7 @@ - deleted_biblio - item - pickup_library + - debits collectionFormat: csv produces: - application/json -- 2.51.0