Bug 23415: (QA follow-up) Move to Circulation::CanBookBeRenewed
This moves the basic calculation for too_much_oweing out of the controller and into the class method. Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
00350eacb4
commit
167a3da258
|
|
@ -3267,9 +3267,11 @@ sub CanBookBeRenewed {
|
|||
&& $issuing_rule->{unseen_renewals_allowed} == ( $issue->unseen_renewals + 1 ) ) ? 1 : 0;
|
||||
|
||||
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
|
||||
my $finesblockrenewing = C4::Context->preference("FineNoRenewals");
|
||||
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
|
||||
my $restricted = $patron->is_debarred;
|
||||
my $hasoverdues = $patron->has_overdues;
|
||||
my $balance = $patron->account->balance;
|
||||
|
||||
if ( $restricted and $restrictionblockrenewing ) {
|
||||
return ( 0, 'restriction' );
|
||||
|
|
@ -3277,6 +3279,8 @@ sub CanBookBeRenewed {
|
|||
|| ( $issue->is_overdue and $overduesblockrenewing eq 'blockitem' ) )
|
||||
{
|
||||
return ( 0, 'overdue' );
|
||||
} elsif ( $finesblockrenewing && $balance > $finesblockrenewing ) {
|
||||
return ( 0, 'too_much_oweing');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,9 +68,6 @@ if ( $op eq 'cud-renew' && $barcode ) {
|
|||
$patron = $checkout->patron;
|
||||
my $borrowernumber = $patron->borrowernumber;
|
||||
|
||||
$balance = $patron->account->balance;
|
||||
my $amountlimit = C4::Context->preference("FineNoRenewals");
|
||||
|
||||
if ( ( $patron->is_debarred || q{} ) lt dt_from_string()->ymd() ) {
|
||||
my $confirmations;
|
||||
my $can_renew;
|
||||
|
|
@ -98,12 +95,15 @@ if ( $op eq 'cud-renew' && $barcode ) {
|
|||
);
|
||||
}
|
||||
|
||||
if ( $balance > $amountlimit ) {
|
||||
$error = "too_much_debt";
|
||||
$can_renew = 0;
|
||||
if ( $error && ($error eq 'too_much_oweing' or $error eq 'auto_too_much_oweing') ) {
|
||||
if ($override_debt) {
|
||||
$can_renew = 1;
|
||||
$error = undef;
|
||||
$error = undef;
|
||||
}
|
||||
else {
|
||||
$balance = $patron->account->balance;
|
||||
$template->param( balance => $balance );
|
||||
$can_renew = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +142,6 @@ if ( $op eq 'cud-renew' && $barcode ) {
|
|||
error => $error,
|
||||
soonestrenewdate => $soonest_renew_date,
|
||||
latestautorenewdate => $latest_auto_renew_date,
|
||||
balance => $balance,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@
|
|||
<button type="submit" class="btn btn-default approve"><i class="fa fa-check"></i> Override limit and renew</button>
|
||||
</form>
|
||||
[% END %]
|
||||
[% ELSIF error == "too_much_debt" %]
|
||||
[% ELSIF error == "too_much_oweing" %]
|
||||
|
||||
<li>The patron has a debt of [% balance | $Price %].</li>
|
||||
<form method="post" action="/cgi-bin/koha/circ/renew.pl">
|
||||
|
|
|
|||
|
|
@ -497,7 +497,7 @@ subtest "GetIssuingCharges tests" => sub {
|
|||
|
||||
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
|
||||
subtest "CanBookBeRenewed tests" => sub {
|
||||
plan tests => 115;
|
||||
plan tests => 116;
|
||||
|
||||
C4::Context->set_preference( 'ItemsDeniedRenewal', '' );
|
||||
|
||||
|
|
@ -1893,6 +1893,8 @@ subtest "CanBookBeRenewed tests" => sub {
|
|||
"Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber"
|
||||
);
|
||||
|
||||
t::lib::Mocks::mock_preference('FineNoRenewals', 0);
|
||||
|
||||
# Recalls
|
||||
t::lib::Mocks::mock_preference( 'UseRecalls', 1 );
|
||||
Koha::CirculationRules->set_rules(
|
||||
|
|
@ -1969,6 +1971,13 @@ subtest "CanBookBeRenewed tests" => sub {
|
|||
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $recall_issue );
|
||||
is( $renewokay, 1, 'Can renew item if biblio-level recall has already been allocated an item' );
|
||||
$recall->set_cancelled;
|
||||
|
||||
# Too much debt
|
||||
t::lib::Mocks::mock_preference('FineNoRenewals', 1);
|
||||
( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1);
|
||||
is( $renewokay, 0, 'Cannot renew, too much debt and FineNoRenewals=1' );
|
||||
is( $error, 'too_much_oweing', 'Cannot renew, debt not allowed (returned code is too_much_oweing)');
|
||||
C4::Context->dbh->do("DELETE FROM accountlines");
|
||||
};
|
||||
|
||||
subtest "CanBookBeRenewed | bookings" => sub {
|
||||
|
|
|
|||
Loading…
Reference in New Issue