Bugzilla – Attachment 185363 Details for
Bug 37344
Patrons with cancelled discharge are seen as discharged when suspended due to overdue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37344: (follow-up) To be squashed
Bug-37344-follow-up-To-be-squashed.patch (text/plain), 5.13 KB, created by
Baptiste Wojtkowski (bwoj)
on 2025-08-13 12:00:55 UTC
(
hide
)
Description:
Bug 37344: (follow-up) To be squashed
Filename:
MIME Type:
Creator:
Baptiste Wojtkowski (bwoj)
Created:
2025-08-13 12:00:55 UTC
Size:
5.13 KB
patch
obsolete
>From b402121fca6b96e5ee89b12f834f3da18370944c Mon Sep 17 00:00:00 2001 >From: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Date: Tue, 12 Aug 2025 16:25:11 +0200 >Subject: [PATCH] Bug 37344: (follow-up) To be squashed > >This fix: >- Solves the issues from qa script >- Update the function to add more consistency >- Add pod documentation >--- > Koha/Patron/Discharge.pm | 75 ++++++++++++++++++++++++++++------------ > 1 file changed, 53 insertions(+), 22 deletions(-) > >diff --git a/Koha/Patron/Discharge.pm b/Koha/Patron/Discharge.pm >index 6f827387d..34bacb322 100644 >--- a/Koha/Patron/Discharge.pm >+++ b/Koha/Patron/Discharge.pm >@@ -95,10 +95,10 @@ sub is_discharged { > return unless $params->{borrowernumber}; > my $borrowernumber = $params->{borrowernumber}; > >- my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred; >- my @validated = get_validated({borrowernumber => $borrowernumber}); >+ my $restricted = Koha::Patrons->find($borrowernumber)->is_debarred; >+ my @validated = get_validated( { borrowernumber => $borrowernumber } ); > >- if ($restricted && @validated) { >+ if ( $restricted && @validated ) { > return 1; > } else { > return 0; >@@ -113,18 +113,6 @@ Place a discharge request on a given borrower after checking the borrower has th > > =cut > >-sub is_discharged { >- my ($params) = @_; >- my $discharge = Koha::Database->new->schema->resultset('Discharge')->search( >- { >- borrower => $params->{borrowernumber}, >- validated => { "not" => undef }, >- cancelled => undef, >- } >- ); >- return $discharge->count > 0; >-} >- > sub request { > my ($params) = @_; > my $borrowernumber = $params->{borrowernumber}; >@@ -141,32 +129,67 @@ sub request { > ); > } > >-=head3 discharge >+=head3 is_cancelled > >- my $request = Koha::Patron:Discharge->discharge({borrowernumber => $borrowernumber}); >+ my $is_cancelled = Koha::Patron:Discharge->is_cancelled({discharge_id => $discharge_id}); > >-Place a discharge request on a given borrower, if a discharge was requested, update the status to discharged and place a suspension on the user. >+Returns true if there is a discharge that has been cancelled and has the given discharge_id, false else. > > =cut > > sub is_cancelled { > my ($params) = @_; >+ unless ( $params->{discharge_id} ) { >+ Koha::Exceptions::BadParameter->throw("is_cancelled must be called with a discharge_id"); >+ } > my $discharge = Koha::Database->new->schema->resultset('Discharge')->search( > { > discharge_id => $params->{discharge_id}, >- cancelled => { "not" => undef }, > } > ); >- return $discharge->count > 0; >+ if ( $discharge->count == 0 ) { >+ Koha::Exceptions::BadParameter->throw("is_cancelled must be called with a valid discharge_id"); >+ } >+ return defined $discharge->single->cancelled; > } > >+=head3 cancel >+ >+ Koha::Patron:Discharge->cancel( >+ discharge_id => $discharge_id, >+ cancellation_reason => $cancellation_reason, >+ borrowernumber => $borrowernumber, >+ }); >+ >+Cancel the discharge given as argument through discharge_id. This will remove suspension associated with the borrowernumber, and update cancellation date and reason. >+ >+=cut >+ > sub cancel { > my ($params) = @_; >- my $discharge = Koha::Database->new->schema->resultset('Discharge')->search( >+ my $discharge = Koha::Database->new->schema->resultset('Discharge')->find( > { > discharge_id => $params->{discharge_id}, > } > ); >+ my $patron = Koha::Patrons->find( { borrowernumber => $params->{borrowernumber} } ); >+ unless ( $patron || $discharge ) { >+ Koha::Exceptions::BadParameter->throw("cancel() must be called either with a borrowernumber or a discharge id"); >+ } >+ if ( $patron && $discharge && ( $discharge->borrower->borrowernumber != $patron->borrowernumber ) ) { >+ Koha::Exceptions::BadParameter->throw( >+ "If passing patron and discharge, the patron and the discharge must correspond"); >+ } >+ if ($discharge) { >+ $patron = Koha::Patrons->find( { borrowernumber => $discharge->borrower->borrowernumber } ); >+ } else { >+ $discharge = Koha::Database->new->schema->resultset('Discharge')->search( >+ { >+ borrower => $patron->borrowernumber, >+ validated => { -not => undef } >+ } >+ )->single; >+ } > $discharge->update( > { > cancelled => dt_from_string, >@@ -175,12 +198,20 @@ sub cancel { > ); > Koha::Patron::Debarments::DelUniqueDebarment( > { >- borrowernumber => $params->{borrowernumber}, >+ borrowernumber => $patron->borrowernumber, > type => "DISCHARGE", > } > ); > } > >+=head3 discharge >+ >+ my $request = Koha::Patron:Discharge->discharge({borrowernumber => $borrowernumber}); >+ >+Place a discharge request on a given borrower, if a discharge was requested, update the status to discharged and place a suspension on the user. >+ >+=cut >+ > sub discharge { > my ($params) = @_; > my $borrowernumber = $params->{borrowernumber}; >-- >2.30.2
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 37344
:
179461
|
179489
|
179763
|
179826
|
179827
|
179828
|
181709
|
182647
|
182648
|
182649
|
182650
|
182747
|
182748
|
182749
|
182750
|
182751
|
182907
|
184427
|
184428
|
184429
|
184430
|
184431
|
185361
|
185362
| 185363 |
185364