From f49f789512d681e44e370a67d12a9094df1e2104 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 --- 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 97145b1..4c679e6 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1149,23 +1149,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}; + } } } @@ -2942,23 +2942,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 697ec83..9f094fd 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.7.4