From 91c57a9e64f7d8a20051518b96483700c64b2dc6 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 8 Nov 2019 10:22:09 +0100 Subject: [PATCH] Bug 15261: Add overlap reserve check in ILS-DI HoldTitle and HoldItem Test plan : - apply the tests patch. - prove t/db_dependent/ILSDI_Services.t => it should fail - apply fix patch and run the tests again. - tests should pass. --- C4/ILSDI/Services.pm | 33 +++++++++++++-------------------- C4/Reserves.pm | 8 ++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index b528e78a46..f0c5fb9d4c 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -796,9 +796,8 @@ sub HoldTitle { my $title = $biblio ? $biblio->title : ''; - # Check if the biblio can be reserved - my $code = CanBookBeReserved( $borrowernumber, $biblionumber )->{status}; - return { code => $code } unless ( $code eq 'OK' ); + my $resdate = $cgi->param('start_date'); + my $expdate = $cgi->param('expiry_date'); my $branch; @@ -814,14 +813,12 @@ sub HoldTitle { return { code => 'libraryNotPickupLocation' } unless $destination->pickup_location; return { code => 'cannotBeTransferred' } unless $biblio->can_be_transferred( { to => $destination } ); - my $resdate = $cgi->param('start_date'); - my $expdate = $cgi->param('expiry_date'); - - if ( C4::Context->preference('PreventReservesOnSamePeriod') - && ReservesOnSamePeriod( $biblionumber, undef, $resdate, $expdate ) ) - { - return { code => 'overlap' }; - } + # Check if the biblio can be reserved + my $code = CanBookBeReserved( + $borrowernumber, $biblionumber, $branch, + { start_date => $resdate, expiry_date => $expdate } + )->{status}; + return { code => $code } unless ( $code eq 'OK' ); # Add the reserve # $branch, $borrowernumber, $biblionumber, @@ -912,18 +909,14 @@ sub HoldItem { $branch = $patron->branchcode; } - # Check for item disponibility - my $canitembereserved = C4::Reserves::CanItemBeReserved( $patron, $item, $branch )->{status}; - return { code => $canitembereserved } unless $canitembereserved eq 'OK'; - my $resdate = $cgi->param('start_date'); my $expdate = $cgi->param('expiry_date'); - if ( C4::Context->preference('PreventReservesOnSamePeriod') - && ReservesOnSamePeriod( $biblionumber, $itemnumber, $resdate, $expdate ) ) - { - return { code => 'overlap' }; - } + # Check for item disponibility + my $canitembereserved = + C4::Reserves::CanItemBeReserved( $patron, $item, $branch, { start_date => $resdate, expiry_date => $expdate } ) + ->{status}; + return { code => $canitembereserved } unless $canitembereserved eq 'OK'; # Add the reserve my $priority = C4::Reserves::CalculatePriority($biblionumber); diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 05e26ebee2..80f2db8339 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -473,6 +473,7 @@ sub CanBookBeReserved { { status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode { status => pickupNotInHoldGroup }, pickup location is not in hold group, and pickup locations are only allowed from hold groups. { status => recall }, if the borrower has already placed a recall on this item + { status => overlap }, if PreventReservesOnSamePeriod is true and reservation dates overlaps with a previous reservation =cut @@ -537,6 +538,13 @@ sub CanItemBeReserved { return _cache { status => 'alreadypossession' }; } + if ( C4::Context->preference('PreventReservesOnSamePeriod') + && ReservesOnSamePeriod( $item->biblionumber, $item->itemnumber, $params->{start_date}, $params->{expiry_date} ) + ) + { + return _cache { status => 'overlap' }; + } + # check if a recall exists on this item from this borrower return _cache { status => 'recall' } if $patron->recalls->filter_by_current->search( { item_id => $item->itemnumber } )->count; -- 2.39.5