From 36dfbe2eb882d95e8ffa7e712b86f4450f658344 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Mon, 2 Aug 2021 19:19:12 -1000 Subject: [PATCH] Bug 15261: Always check preference PreventCheckoutOnSameReservePeriod first https://bugs.koha-community.org/show_bug.cgi?id=1526 --- C4/Circulation.pm | 67 ++++++++++++++++++++++---------------------- opac/opac-reserve.pl | 5 ++-- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 5ac47093e8..d686a56b20 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1151,23 +1151,23 @@ sub CanBookBeIssued { } } - my $now = dt_from_string(); - my $preventCheckoutOnSameReservePeriod = - C4::Context->preference("PreventCheckoutOnSameReservePeriod"); - my $reserves_on_same_period = - ReservesOnSamePeriod($item_object->biblionumber, $item_object->itemnumber, $now->ymd, $duedate->ymd); - if ($preventCheckoutOnSameReservePeriod && $reserves_on_same_period) { - my $reserve = $reserves_on_same_period->[0]; - if ($reserve->{borrowernumber} ne $patron->borrowernumber) { - my $patron = Koha::Patrons->find( $reserve->{borrowernumber} ); - $needsconfirmation{RESERVED} = 1; - $needsconfirmation{resfirstname} = $patron->firstname; - $needsconfirmation{ressurname} = $patron->surname; - $needsconfirmation{rescardnumber} = $patron->cardnumber; - $needsconfirmation{resborrowernumber} = $patron->borrowernumber; - $needsconfirmation{resbranchcode} = $patron->branchcode; - $needsconfirmation{resreservedate} = $reserve->{reservedate}; - $needsconfirmation{reserve_id} = $reserve->{reserve_id}; + if ( C4::Context->preference("PreventCheckoutOnSameReservePeriod") ) { + my $now = dt_from_string(); + my $reserves_on_same_period = + ReservesOnSamePeriod($item_object->biblionumber, $item_object->itemnumber, $now->ymd, $duedate->ymd); + if ($reserves_on_same_period) { + my $reserve = $reserves_on_same_period->[0]; + if ($reserve->{borrowernumber} ne $patron->borrowernumber) { + my $patron = Koha::Patrons->find( $reserve->{borrowernumber} ); + $needsconfirmation{RESERVED} = 1; + $needsconfirmation{resfirstname} = $patron->firstname; + $needsconfirmation{ressurname} = $patron->surname; + $needsconfirmation{rescardnumber} = $patron->cardnumber; + $needsconfirmation{resborrowernumber} = $patron->borrowernumber; + $needsconfirmation{resbranchcode} = $patron->branchcode; + $needsconfirmation{resreservedate} = $reserve->{reservedate}; + $needsconfirmation{reserve_id} = $reserve->{reserve_id}; + } } } @@ -2849,23 +2849,22 @@ sub CanBookBeRenewed { } } - unless ($date_due) { - my $itemtype = $item->effective_itemtype; - my $patron_unblessed = $patron->unblessed; - $date_due = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? - dt_from_string( $issue->date_due, 'sql' ) : - dt_from_string(); - $date_due = CalcDateDue($date_due, $itemtype, _GetCircControlBranch($item->unblessed(), $patron_unblessed), $patron_unblessed, 'is a renewal'); - } - - my $now = dt_from_string(); - my $biblionumber = $item->biblionumber; - my $preventCheckoutOnSameReservePeriod = - C4::Context->preference("PreventCheckoutOnSameReservePeriod"); - my $reserves_on_same_period = - ReservesOnSamePeriod($biblionumber, $itemnumber, $now->ymd, $date_due->ymd); - if ($preventCheckoutOnSameReservePeriod && $reserves_on_same_period) { - $resfound = 1; + if ( C4::Context->preference("PreventCheckoutOnSameReservePeriod") ) { + unless ($date_due) { + my $itemtype = $item->effective_itemtype; + my $patron_unblessed = $patron->unblessed; + $date_due = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? + dt_from_string( $issue->date_due, 'sql' ) : + dt_from_string(); + $date_due = CalcDateDue($date_due, $itemtype, _GetCircControlBranch($item->unblessed(), $patron_unblessed), $patron_unblessed, 'is a renewal'); + } + my $now = dt_from_string(); + my $biblionumber = $item->biblionumber; + my $reserves_on_same_period = + ReservesOnSamePeriod($biblionumber, $itemnumber, $now->ymd, $date_due->ymd); + if ($reserves_on_same_period) { + $resfound = 1; + } } if( $cron ) { #The cron wants to return 'too_soon' over 'on_reserve' diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 93b66b57d0..7bfe505aa4 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -286,9 +286,8 @@ if ( $query->param('place_reserve') ) { $itemNum = undef; } - if ($canreserve) { - if (C4::Context->preference("PreventReservesOnSamePeriod") && - ReservesOnSamePeriod($biblioNum, $itemNum, $startdate, $expiration_date)) { + if ( $canreserve && C4::Context->preference("PreventReservesOnSamePeriod") ) { + if ( ReservesOnSamePeriod($biblioNum, $itemNum, $startdate, $expiration_date) ) { $canreserve = 0; $failed_holds++; } -- 2.30.2