From 943ae0b275c91a5405d33163045e92516911875c Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Wed, 7 Aug 2024 14:18:20 +0200 Subject: [PATCH] Bug 14250: Patron with fines cannot be discharged anymore TEST PLAN: 1 - In the intranet add fines to a client and ensure they have no checkout 2 - Set syspref useDischarge to 'Allow' 3 - On client profile click on "Discharge", see it is possible 4 - On the opac, go to the tab "Ask for discharge", see it is possible 5 - Apply patch 6 - Click on the button "Ask for discharge" -> it will not be possible and you will be propperly messaged 7 - Return to the tab "Ask for a discharge", there will be no button anymore 8 - On the intranet page, there will be no button anymore 9 - Check out a book 10 - Repeat 7 and 8 and see the message include issue with checkout 11 - Remove fine and repeat 7 & 8 --- Koha/Patron/Discharge.pm | 7 +++++- .../prog/en/modules/members/discharge.tt | 11 +++++++- .../bootstrap/en/modules/opac-discharge.tt | 25 ++++++++++++++++--- members/discharge.pl | 6 +++++ opac/opac-discharge.pl | 14 ++++++++--- t/db_dependent/Patron/Borrower_Discharge.t | 25 ++++++++++++++++--- 6 files changed, 76 insertions(+), 12 deletions(-) diff --git a/Koha/Patron/Discharge.pm b/Koha/Patron/Discharge.pm index f86d4d7..3f3aeab 100644 --- a/Koha/Patron/Discharge.pm +++ b/Koha/Patron/Discharge.pm @@ -40,7 +40,12 @@ sub can_be_discharged { return unless $patron; my $has_pending_checkouts = $patron->checkouts->count; - return $has_pending_checkouts ? 0 : 1; + return 0 if $has_pending_checkouts; + + my $has_debt = ($patron->account->outstanding_debits->total_outstanding > 0); + return 0 if $has_debt; + + return 1; } sub is_discharged { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt index fd2a5b2..51c43c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/discharge.tt @@ -52,7 +52,16 @@ [% END %] [% UNLESS can_be_discharged %] -

Cannot edit discharge: the patron has checked out items.

+

Cannot edit discharge for following reasons:

+ [% ELSE %] [% IF patron.holds.count %]

Patron has holds. They will be cancelled if the discharge is generated.

diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt index 96f019d..d6df61d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-discharge.tt @@ -43,14 +43,33 @@ Get your discharge [% ELSIF pending %]

Your discharge will be available on this page within a few days.

- [% ELSIF has_issues %] + [% ELSIF failure %]

You cannot be discharged, you have checked out items. Please return items before asking for a discharge.

+ [% ELSIF not messages %]

What is a discharge?

This document certifies that you have returned all borrowed items. It is sometimes asked during a file transfer from a school to another. The discharge is sent by us to your school. You will also find it available on your reader account.

Warning: This request is only valid if you are in good standing with the library. Once the application is made, you can not borrow library materials.

- [% IF has_checkouts %] -
You cannot be discharged, you have checked out items. Please return items before asking for a discharge.
+ [% UNLESS can_be_discharged %] +
You cannot be discharged for following reasons: + +
[% ELSE %]
[% INCLUDE 'csrf-token.inc' %] diff --git a/members/discharge.pl b/members/discharge.pl index 10002e2..676a095 100755 --- a/members/discharge.pl +++ b/members/discharge.pl @@ -65,6 +65,12 @@ my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $borrowernumber }); + +unless ( $can_be_discharged ) { + my $has_checkout = $patron->checkouts->count; + my $has_fine = $patron->account->outstanding_debits->total_outstanding +} + # Generating discharge if needed if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) { my $is_discharged = Koha::Patron::Discharge::is_discharged({ diff --git a/opac/opac-discharge.pl b/opac/opac-discharge.pl index d232ea5..49d1e6c 100755 --- a/opac/opac-discharge.pl +++ b/opac/opac-discharge.pl @@ -44,9 +44,13 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ }); my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $loggedinuser }); -if ($can_be_discharged == 0) { - $template->param( has_checkouts => 1 ); -} +my $patron = Koha::Patrons->find( $loggedinuser ); +my $has_pending_checkouts = $patron->checkouts->count; +my $has_debt = ($patron->account->outstanding_debits->total_outstanding > 0); + +$template->param( can_be_discharged => $can_be_discharged ); +$template->param( has_checkouts => $has_pending_checkouts ); +$template->param( has_debt => $has_debt ); my $pending = Koha::Patron::Discharge::count({ borrowernumber => $loggedinuser, @@ -67,7 +71,9 @@ if ( $op eq 'cud-request' ) { $template->param( success => 1 ); } else { - $template->param( has_issues => 1 ); + $template->param( failure => 1 ); + $template->param( has_issues => $has_pending_checkouts ); + $template->param( has_debt => $has_debt ); } } elsif ( $op eq 'get' ) { diff --git a/t/db_dependent/Patron/Borrower_Discharge.t b/t/db_dependent/Patron/Borrower_Discharge.t index 6c06ecf..ba1c151 100755 --- a/t/db_dependent/Patron/Borrower_Discharge.t +++ b/t/db_dependent/Patron/Borrower_Discharge.t @@ -16,7 +16,7 @@ use Modern::Perl; -use Test::More tests => 23; +use Test::More tests => 25; use Test::MockModule; use Test::Warn; @@ -90,10 +90,29 @@ is( Koha::Patron::Discharge::discharge({ borrowernumber => $patron->borrowernumb is_deeply( [ Koha::Patron::Discharge::get_pendings ], [], 'There is no pending discharge request' ); is_deeply( [ Koha::Patron::Discharge::get_validated ], [], 'There is no validated discharge' ); +# Discharge not possible with issues and fines +$patron->account->add_debit( + { + amount => 0.1, + interface => C4::Context->interface, + type => 'OVERDUE' + } +); +is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with fines and checkouts cannot be discharged' ); + AddReturn( $barcode ); -# Discharge possible without issue -is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 1, 'A patron without issues can be discharged' ); +is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 0, 'A patron with fines cannot be discharged' ); + + +$patron->account->pay( + { + amount => 0.1, + } +); + +# Discharge possible without issue or fine +is( Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $patron->borrowernumber }), 1, 'A patron without issues or fines can be discharged' ); is(Koha::Patron::Discharge::generate_as_pdf,undef,"Confirm failure when lacking borrower number"); -- 2.43.0