From 6a2f904494959cd76027d0d3e35b79cbac11b082 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 Signed-off-by: Roman Dolny Signed-off-by: Kyle M Hall --- Koha/Patron/Discharge.pm | 7 +++- .../prog/en/modules/members/discharge.tt | 13 +++++++- .../bootstrap/en/modules/opac-discharge.tt | 29 +++++++++++++++-- members/discharge.pl | 6 ++++ opac/opac-discharge.pl | 16 +++++++--- t/db_dependent/Patron/Borrower_Discharge.t | 32 +++++++++++++++++-- 6 files changed, 90 insertions(+), 13 deletions(-) diff --git a/Koha/Patron/Discharge.pm b/Koha/Patron/Discharge.pm index f86d4d77eec..a72f7f2b7b3 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 fd2a5b241f5..9353e2cd45d 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,18 @@ [% END %] [% UNLESS can_be_discharged %] -

Cannot edit discharge: the patron has checked out items.

+

Cannot edit discharge for following reasons:

+
    + [% IF patron.checkouts.count %] +
  • They have checked out items
  • + [% END %] + [% IF (patron.account.outstanding_debits.total_outstanding > 0) %] +
  • They have unpaid fines
  • + [% END %] + [% IF patron.checkouts.count == 0 and (patron.account.outstanding_debits.total_outstanding == 0) %] +
  • Patron cannot be discharged for an unknown reason, please contact a librarian for more information
  • + [% END %] +
[% 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 6f061b22caa..b0330a57aaa 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,37 @@ 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.

+
    + [% IF has_debt %] +
  • You have unpaid fines. Please pay your fines before reapplying.
  • + [% END %] + [% IF has_issues %] +
  • You have checked out items. Please return them before reapplying.
  • + [% END %] + [% IF !has_issue and !has_debt %] +
  • Patron cannot be discharged for an unknown reason, please contact a librarian for more information
  • + [% END %] +
[% 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: +
    + [% IF has_debt %] +
  • You have unpaid fines. Please pay your fines before reapplying.
  • + [% END %] + [% IF has_checkouts %] +
  • You have checked out items. Please return them before reapplying.
  • + [% END %] + [% IF !has_checkouts and !has_debt %] +
  • Patron cannot be discharged for an unknown reason, please contact a librarian for more information
  • + [% END %] +
+
[% ELSE %] Ask for a discharge [% END %] diff --git a/members/discharge.pl b/members/discharge.pl index 10002e21c5c..2742bad084a 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 d232ea57222..5e6869be444 100755 --- a/opac/opac-discharge.pl +++ b/opac/opac-discharge.pl @@ -43,10 +43,14 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ type => "opac", }); -my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged({ borrowernumber => $loggedinuser }); -if ($can_be_discharged == 0) { - $template->param( has_checkouts => 1 ); -} +my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } ); +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 062a61076e0..1ebbdc633df 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; @@ -91,10 +91,36 @@ 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.39.2