Bug 19198: Renewal as issue causes too many error

This patch moves some code and prevents checking for too many checkouts
when performing a renewal via checkout

To test:
1 - Set a rule to limit checkouts to a single issue, allowing renewal
2 - Issue an item to a patron
3 - Issue the same item
4 - In staff client you get a confirm to renew and a notice of Too Many
checkouts, don't confirm
5 - VIA Sip - you get a renewal response, but in logs the renewal fails
as a 'too
6 - Apply patch
7 - Via staff client you shoudl get renewal confirm with no too many
error
8 - SIP checkout should renew

Signed-off-by: Lee Jamison <ldjamison@marywood.edu>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Nick Clemens 2017-08-29 14:25:20 +00:00 committed by Jonathan Druart
parent 7d3eefd8f1
commit c204171ff3
1 changed files with 51 additions and 51 deletions

View File

@ -834,6 +834,56 @@ sub CanBookBeIssued {
}
}
#
# CHECK IF BOOK ALREADY ISSUED TO THIS BORROWER
#
if ( $issue && $issue->borrowernumber eq $borrower->{'borrowernumber'} ){
# Already issued to current borrower.
# If it is an on-site checkout if it can be switched to a normal checkout
# or ask whether the loan should be renewed
if ( $issue->onsite_checkout
and C4::Context->preference('SwitchOnSiteCheckouts') ) {
$messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
} else {
my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
$borrower->{'borrowernumber'},
$item->{'itemnumber'},
);
if ( $CanBookBeRenewed == 0 ) { # no more renewals allowed
if ( $renewerror eq 'onsite_checkout' ) {
$issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
}
else {
$issuingimpossible{NO_MORE_RENEWALS} = 1;
}
}
else {
$needsconfirmation{RENEW_ISSUE} = 1;
}
}
}
elsif ( $issue ) {
# issued to someone else
my $patron = Koha::Patrons->find( $issue->borrowernumber );
my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
unless ( $can_be_returned ) {
$issuingimpossible{RETURN_IMPOSSIBLE} = 1;
$issuingimpossible{branch_to_return} = $message;
} else {
$needsconfirmation{ISSUED_TO_ANOTHER} = 1;
$needsconfirmation{issued_firstname} = $patron->firstname;
$needsconfirmation{issued_surname} = $patron->surname;
$needsconfirmation{issued_cardnumber} = $patron->cardnumber;
$needsconfirmation{issued_borrowernumber} = $patron->borrowernumber;
}
}
# JB34 CHECKS IF BORROWERS DON'T HAVE ISSUE TOO MANY BOOKS
#
my $switch_onsite_checkout = (
@ -843,7 +893,7 @@ sub CanBookBeIssued {
and $issue->borrowernumber == $borrower->{'borrowernumber'} ? 1 : 0 );
my $toomany = TooMany( $borrower, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
# if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
if ( $toomany ) {
if ( $toomany & !$needsconfirmation{RENEW_ISSUE} ) {
if ( $toomany->{max_allowed} == 0 ) {
$needsconfirmation{PATRON_CANT} = 1;
}
@ -944,56 +994,6 @@ sub CanBookBeIssued {
}
}
#
# CHECK IF BOOK ALREADY ISSUED TO THIS BORROWER
#
if ( $issue && $issue->borrowernumber eq $borrower->{'borrowernumber'} ){
# Already issued to current borrower.
# If it is an on-site checkout if it can be switched to a normal checkout
# or ask whether the loan should be renewed
if ( $issue->onsite_checkout
and C4::Context->preference('SwitchOnSiteCheckouts') ) {
$messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
} else {
my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
$borrower->{'borrowernumber'},
$item->{'itemnumber'},
);
if ( $CanBookBeRenewed == 0 ) { # no more renewals allowed
if ( $renewerror eq 'onsite_checkout' ) {
$issuingimpossible{NO_RENEWAL_FOR_ONSITE_CHECKOUTS} = 1;
}
else {
$issuingimpossible{NO_MORE_RENEWALS} = 1;
}
}
else {
$needsconfirmation{RENEW_ISSUE} = 1;
}
}
}
elsif ( $issue ) {
# issued to someone else
my $patron = Koha::Patrons->find( $issue->borrowernumber );
my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
unless ( $can_be_returned ) {
$issuingimpossible{RETURN_IMPOSSIBLE} = 1;
$issuingimpossible{branch_to_return} = $message;
} else {
$needsconfirmation{ISSUED_TO_ANOTHER} = 1;
$needsconfirmation{issued_firstname} = $patron->firstname;
$needsconfirmation{issued_surname} = $patron->surname;
$needsconfirmation{issued_cardnumber} = $patron->cardnumber;
$needsconfirmation{issued_borrowernumber} = $patron->borrowernumber;
}
}
unless ( $ignore_reserves ) {
# See if the item is on reserve.
my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );