Bugzilla – Attachment 153477 Details for
Bug 34277
Add an API endpoint to return all patrons with outstanding charges
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34277: Add a patrons with outstanding charges endpoint
Bug-34277-Add-a-patrons-with-outstanding-charges-e.patch (text/plain), 5.83 KB, created by
Matt Blenkinsop
on 2023-07-14 12:54:11 UTC
(
hide
)
Description:
Bug 34277: Add a patrons with outstanding charges endpoint
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2023-07-14 12:54:11 UTC
Size:
5.83 KB
patch
obsolete
>From 71c5dc36e9545804515a2930fbdaa06105e8a183 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Fri, 14 Jul 2023 12:49:44 +0000 >Subject: [PATCH] Bug 34277: Add a patrons with outstanding charges endpoint > >This patch adds an endpoint to return all patrons with outstanding debits/credits on their account. Currently this can't be achieved through the API without looping through all patrons using /patrons/{patron_id}/account > >Test plan: >1) Apply patch >2) Add some charges/credits to some patron accounts >3) Call /api/v1/patrons/get_balances >4) An array should be returned with all the patrons that you added charges to >--- > Koha/REST/V1/Patrons/Account.pm | 48 +++++++++++++++++++ > .../swagger/definitions/patron_balance.yaml | 3 ++ > api/v1/swagger/paths/patrons_account.yaml | 44 +++++++++++++++++ > api/v1/swagger/swagger.yaml | 2 + > 4 files changed, 97 insertions(+) > >diff --git a/Koha/REST/V1/Patrons/Account.pm b/Koha/REST/V1/Patrons/Account.pm >index 95c998ad56..2929c55e0e 100644 >--- a/Koha/REST/V1/Patrons/Account.pm >+++ b/Koha/REST/V1/Patrons/Account.pm >@@ -61,6 +61,7 @@ sub get { > status => 200, > openapi => { > balance => $account->balance, >+ borrowernumber => $patron->borrowernumber, > outstanding_debits => { > total => $debits->total_outstanding, > lines => $debits->to_api >@@ -295,4 +296,51 @@ sub add_debit { > }; > } > >+=head3 get_patron_balances >+ >+=cut >+ >+sub get_patron_balances { >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my @patrons_with_outstanding_balances; >+ my $patrons_rs = Koha::Patrons->search()->as_list; >+ >+ foreach my $patron ( @{ $patrons_rs } ) { >+ my $account = $patron->account; >+ my $balance = $account->balance; >+ my $debits = $account->outstanding_debits; >+ my $credits = $account->outstanding_credits; >+ my $total_debits = $debits->total_outstanding; >+ my $total_credits = $credits->total_outstanding; >+ >+ if($total_debits != 0 || $total_credits != 0) { >+ my $patron_account_detail = { >+ borrowernumber => $patron->borrowernumber, >+ balance => $balance, >+ outstanding_debits => { >+ total => $total_debits, >+ lines => $debits->to_api >+ }, >+ outstanding_credits => { >+ total => $total_credits, >+ lines => $credits->to_api >+ } >+ }; >+ push @patrons_with_outstanding_balances, $patron_account_detail; >+ } >+ } >+ >+ return $c->render( >+ status => 200, >+ openapi => \@patrons_with_outstanding_balances >+ ); >+ >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/definitions/patron_balance.yaml b/api/v1/swagger/definitions/patron_balance.yaml >index 7d40cb3af6..81da010c1a 100644 >--- a/api/v1/swagger/definitions/patron_balance.yaml >+++ b/api/v1/swagger/definitions/patron_balance.yaml >@@ -1,6 +1,9 @@ > --- > type: object > properties: >+ borrowernumber: >+ type: number >+ description: borrower id number > balance: > type: number > description: Signed decimal number >diff --git a/api/v1/swagger/paths/patrons_account.yaml b/api/v1/swagger/paths/patrons_account.yaml >index 1a282ab1cf..49e49ffa7b 100644 >--- a/api/v1/swagger/paths/patrons_account.yaml >+++ b/api/v1/swagger/paths/patrons_account.yaml >@@ -226,3 +226,47 @@ > x-koha-authorization: > permissions: > updatecharges: remaining_permissions >+"/patrons/get_balances": >+ get: >+ x-mojo-to: Patrons::Account#get_patron_balances >+ operationId: listPatronsWithBalances >+ tags: >+ - patrons >+ - account >+ summary: List patron outstanding balances >+ produces: >+ - application/json >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/match" >+ - $ref: "../swagger.yaml#/parameters/order_by" >+ - $ref: "../swagger.yaml#/parameters/page" >+ - $ref: "../swagger.yaml#/parameters/per_page" >+ - $ref: "../swagger.yaml#/parameters/q_param" >+ - $ref: "../swagger.yaml#/parameters/q_body" >+ responses: >+ "200": >+ description: A list of patrons with outstanding balances >+ schema: >+ type: array >+ items: >+ $ref: "../swagger.yaml#/definitions/patron_balance" >+ "403": >+ description: Access forbidden >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Patron not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "500": >+ description: Internal error >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ borrowers: edit_borrowers >+ updatecharges: remaining_permissions >\ No newline at end of file >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 4eebfdf23d..60844f66b9 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -297,6 +297,8 @@ paths: > $ref: ./paths/patrons.yaml#/~1patrons > "/patrons/{patron_id}": > $ref: "./paths/patrons.yaml#/~1patrons~1{patron_id}" >+ "/patrons/get_balances": >+ $ref: "./paths/patrons_account.yaml#/~1patrons~1get_balances" > "/patrons/{patron_id}/account": > $ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account" > "/patrons/{patron_id}/account/credits": >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34277
: 153477 |
153478
|
154516
|
156185
|
156186
|
156187