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 Bug 14250: (QA follow-up) Deduplicate checks Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Bug 14250: (follow-up) Update messages Update the text for the reasons the patron cannot be discharged. Bug 14250: (follow-up) Refacto the algorithm for discharge messages 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 Note: removing the useless has_checkout and has_debt Bug 14250: (follow-up) Refacto discharge messages display The script that determines if one should display messages to the user, informing him whether they are allowed or not to ask for a discharge is quite hard to understand. For sake of readability, transforming the unless to an if since the error behaviour was in the unless and the success in the else. Changing to success behaviour in the if and failure in the else. Bug 14250: Tidy Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
0075ca7356
commit
2fcb2145c2
|
|
@ -38,8 +38,22 @@ sub can_be_discharged {
|
|||
my $patron = Koha::Patrons->find( $params->{borrowernumber} );
|
||||
return unless $patron;
|
||||
|
||||
my $has_pending_checkouts = $patron->checkouts->count;
|
||||
return $has_pending_checkouts ? 0 : 1;
|
||||
my $can_be_discharged = 1;
|
||||
my $problems = {};
|
||||
|
||||
my $checkouts = $patron->checkouts->count;
|
||||
if ($checkouts) {
|
||||
$can_be_discharged = 0;
|
||||
$problems->{checkouts} = $checkouts;
|
||||
}
|
||||
|
||||
my $debt = $patron->account->outstanding_debits->total_outstanding;
|
||||
if ( $debt > 0 ) {
|
||||
$can_be_discharged = 0;
|
||||
$problems->{debt} = $debt;
|
||||
}
|
||||
|
||||
return ( $can_be_discharged, $problems );
|
||||
}
|
||||
|
||||
sub is_discharged {
|
||||
|
|
@ -61,7 +75,8 @@ sub request {
|
|||
my ($params) = @_;
|
||||
my $borrowernumber = $params->{borrowernumber};
|
||||
return unless $borrowernumber;
|
||||
return unless can_be_discharged( { borrowernumber => $borrowernumber } );
|
||||
my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
|
||||
return unless $can;
|
||||
|
||||
my $rs = Koha::Database->new->schema->resultset('Discharge');
|
||||
return $rs->create(
|
||||
|
|
@ -75,7 +90,9 @@ sub request {
|
|||
sub discharge {
|
||||
my ($params) = @_;
|
||||
my $borrowernumber = $params->{borrowernumber};
|
||||
return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
|
||||
|
||||
my ($can) = can_be_discharged( { borrowernumber => $borrowernumber } );
|
||||
return unless $borrowernumber and $can;
|
||||
|
||||
# Cancel reserves
|
||||
my $patron = Koha::Patrons->find($borrowernumber);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
[% USE Koha %]
|
||||
[% USE Asset %]
|
||||
[% USE KohaDates %]
|
||||
[% USE Price %]
|
||||
[% USE AuthorisedValues %]
|
||||
[% USE Branches %]
|
||||
[% PROCESS 'i18n.inc' %]
|
||||
|
|
@ -52,10 +53,23 @@
|
|||
</div>
|
||||
[% END %]
|
||||
[% UNLESS can_be_discharged %]
|
||||
<p>Cannot edit discharge: the patron has checked out items.</p>
|
||||
<p>A discharge cannot be generated for this patron because:</p>
|
||||
<ul>
|
||||
[% IF discharge_problems.checkouts %]
|
||||
<li>The patron has [% discharge_problems.checkouts | html %] item(s) checked out</li>
|
||||
[% END %]
|
||||
|
||||
[% IF discharge_problems.debt %]
|
||||
<li>The patron has unpaid charges of [% discharge_problems.debt | $Price %]</li>
|
||||
[% END %]
|
||||
</ul>
|
||||
[% ELSE %]
|
||||
[% IF patron.holds.count %]
|
||||
<p>Patron has holds. They will be cancelled if the discharge is generated.</p>
|
||||
<p>The patron has holds. The holds will be cancelled if the discharge is generated.</p>
|
||||
[% END %]
|
||||
|
||||
[% IF discharge_problems.debt %]
|
||||
<li>The patron has unpaid charges of [% discharge_problems.debt | $Price %]</li>
|
||||
[% END %]
|
||||
<div class="btn-toolbar">
|
||||
<form method="post">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[% USE raw %]
|
||||
[% USE Koha %]
|
||||
[% USE Price %]
|
||||
[% USE AdditionalContents %]
|
||||
[% SET OpacNav = AdditionalContents.get( location => "OpacNav", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
|
||||
[% SET OpacNavBottom = AdditionalContents.get( location => "OpacNavBottom", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %]
|
||||
|
|
@ -41,8 +42,6 @@
|
|||
<p><a href="/cgi-bin/koha/opac-discharge.pl?op=get">Get your discharge</a></p>
|
||||
[% ELSIF pending %]
|
||||
<p>Your discharge will be available on this page within a few days.</p>
|
||||
[% ELSIF has_issues %]
|
||||
<p>You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</p>
|
||||
[% ELSIF not messages %]
|
||||
<h2>What is a discharge?</h2>
|
||||
<p
|
||||
|
|
@ -50,14 +49,28 @@
|
|||
available on your reader account.</p
|
||||
>
|
||||
<p><strong>Warning</strong>: 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.</p>
|
||||
[% IF has_checkouts %]
|
||||
<div class="alert alert-info">You cannot be discharged, you have checked out items. Please return items before asking for a discharge.</div>
|
||||
[% ELSE %]
|
||||
[% IF can_be_discharged %]
|
||||
<form action="/cgi-bin/koha/opac-discharge.pl" method="post">
|
||||
[% INCLUDE 'csrf-token.inc' %]
|
||||
<input type="hidden" name="op" value="cud-request" />
|
||||
<button class="btn btn-primary" type="submit">Ask for a discharge</button>
|
||||
</form>
|
||||
[% ELSE %]
|
||||
[% IF failure %]
|
||||
<p> There was an error during the discharge process </p>
|
||||
[% END %]
|
||||
<div class="alert alert-info"
|
||||
>You cannot be discharged because:
|
||||
<ul>
|
||||
[% IF discharge_problems.checkouts %]
|
||||
<li> You have [% discharge_problems.checkouts | html %] item(s) checked out. Please return your checked out items before reapplying. </li>
|
||||
[% END %]
|
||||
|
||||
[% IF discharge_problems.debt %]
|
||||
<li> You have unpaid charges of [% discharge_problems.debt | $Price %]. Please pay your charges before reapplying. </li>
|
||||
[% END %]
|
||||
</ul>
|
||||
</div>
|
||||
[% END %]
|
||||
[% END %]
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ output_and_exit_if_error(
|
|||
{ module => 'members', logged_in_user => $logged_in_user, current_patron => $patron }
|
||||
);
|
||||
|
||||
my $can_be_discharged = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
|
||||
my ( $can_be_discharged, $discharge_problems ) =
|
||||
Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $borrowernumber } );
|
||||
|
||||
# Generating discharge if needed
|
||||
if ( $op eq 'cud-discharge' && $input->param('discharge') and $can_be_discharged ) {
|
||||
|
|
@ -112,6 +113,7 @@ my @validated_discharges = Koha::Patron::Discharge::get_validated(
|
|||
$template->param(
|
||||
patron => $patron,
|
||||
can_be_discharged => $can_be_discharged,
|
||||
discharge_problems => $discharge_problems,
|
||||
validated_discharges => \@validated_discharges,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -45,10 +45,15 @@ 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 ( $can_be_discharged, $discharge_problems ) =
|
||||
Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $loggedinuser } );
|
||||
my $patron = Koha::Patrons->find($loggedinuser);
|
||||
my $has_pending_checkouts = $patron->checkouts->count;
|
||||
|
||||
$template->param(
|
||||
can_be_discharged => $can_be_discharged,
|
||||
discharge_problems => $discharge_problems,
|
||||
);
|
||||
|
||||
my $pending = Koha::Patron::Discharge::count(
|
||||
{
|
||||
|
|
@ -73,7 +78,7 @@ if ( $op eq 'cud-request' ) {
|
|||
if ($success) {
|
||||
$template->param( success => 1 );
|
||||
} else {
|
||||
$template->param( has_issues => 1 );
|
||||
$template->param( failure => 1 );
|
||||
}
|
||||
} elsif ( $op eq 'get' ) {
|
||||
unless ($available) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 23;
|
||||
use Test::More tests => 32;
|
||||
|
||||
use Test::MockModule;
|
||||
use Test::Warn;
|
||||
|
|
@ -89,10 +89,10 @@ $builder->build_sample_item(
|
|||
);
|
||||
|
||||
AddIssue( $patron, $barcode );
|
||||
is(
|
||||
Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 0,
|
||||
'A patron with issues cannot be discharged'
|
||||
);
|
||||
my ( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
|
||||
is( $can, 0, 'A patron with issues cannot be discharged' );
|
||||
is( $problems->{checkouts}, 1, "Patron has checkouts" );
|
||||
is( $problems->{debt}, undef, "Patron has no debt" );
|
||||
|
||||
is(
|
||||
Koha::Patron::Discharge::request( { borrowernumber => $patron->borrowernumber } ), undef,
|
||||
|
|
@ -105,13 +105,46 @@ is(
|
|||
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'
|
||||
}
|
||||
);
|
||||
|
||||
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
|
||||
is(
|
||||
$can, 0,
|
||||
'A patron with fines and checkouts cannot be discharged'
|
||||
);
|
||||
is( $problems->{checkouts}, 1, "Patron has checkouts" );
|
||||
is( $problems->{debt}, 0.1, "Patron has debt" );
|
||||
|
||||
AddReturn($barcode);
|
||||
|
||||
# Discharge possible without issue
|
||||
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
|
||||
is(
|
||||
Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } ), 1,
|
||||
'A patron without issues can be discharged'
|
||||
$can, 0,
|
||||
'A patron with fines cannot be discharged'
|
||||
);
|
||||
is( $problems->{checkouts}, undef, "Patron has checkouts" );
|
||||
is( $problems->{debt}, 0.1, "Patron has debt" );
|
||||
|
||||
$patron->account->pay(
|
||||
{
|
||||
amount => 0.1,
|
||||
}
|
||||
);
|
||||
|
||||
# Discharge possible without issue or fine
|
||||
( $can, $problems ) = Koha::Patron::Discharge::can_be_discharged( { borrowernumber => $patron->borrowernumber } );
|
||||
is(
|
||||
$can, 1,
|
||||
'A patron without issues or fines can be discharged'
|
||||
);
|
||||
is( scalar keys %$problems, 0, "No dishcharge problems found" );
|
||||
|
||||
is( Koha::Patron::Discharge::generate_as_pdf, undef, "Confirm failure when lacking borrower number" );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue