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:
Martin Renvoize 2024-02-16 14:57:33 +00:00 committed by Martin Renvoize
parent 00350eacb4
commit 167a3da258
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
4 changed files with 22 additions and 10 deletions

View File

@ -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');
}
}

View File

@ -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,
);
}

View File

@ -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">

View File

@ -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 {