From 4efd13346869650dd7f3753c0f3537abe0833ff1 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 23 Apr 2015 11:54:40 +0200 Subject: [PATCH] Bug 11999: Check for age restriction in CanBookBeReserved + improve t/db_dependent/Reserves.t to make tests pass on UNIMARC installation Maxreserves and alreadyreserved works on ILSDI Maxreserves works also on staff and opac Already reserves works also on staff and opac tests on t/db_dependent/Reserves.t and t/db_dependent/Holds.t passe (using koha_ut db) Signed-off-by: Alex Arnaud --- C4/Reserves.pm | 11 +++++++++-- t/db_dependent/Reserves.t | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index f57b428e1f..dd76abdcc8 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -289,6 +289,12 @@ sub CanBookBeReserved{ return { status => 'tooManyReserves' }; } + # Check for the age restriction + my $biblioData = C4::Biblio::GetBiblioData( $biblionumber ); + my $borrower = $patron->unblessed; + my ($ageRestriction, $daysToAgeRestriction) = C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower ); + return { status => 'ageRestricted' } if $daysToAgeRestriction && $daysToAgeRestriction > 0; + my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber"); #get items linked via host records @@ -320,6 +326,7 @@ sub CanBookBeReserved{ { status => libraryNotFound }, if given branchcode is not an existing library { status => libraryNotPickupLocation }, if given branchcode is not configured to be a pickup location { status => cannotBeTransferred }, if branch transfer limit applies on given item and branchcode + { status => alreadyReserved }, if the borrower has already reserved this item. =cut @@ -359,14 +366,14 @@ sub CanItemBeReserved { if ( $hold->itemnumber == $itemnumber or $hold->biblionumber == $item->{biblionumber} ) { - return 'alreadyReserved'; + return { status => 'alreadyReserved' }; } } # Check if borrower has reached the maximum number of holds allowed my $maxreserves = C4::Context->preference('maxreserves'); if ($maxreserves && $holds->count >= $maxreserves) { - return 'tooManyReserves'; + return { status => 'tooManyReserves' }; } my $controlbranch = C4::Context->preference('ReservesControlBranch'); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 27b2701ab6..76b5baa210 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -59,7 +59,11 @@ my $frameworkcode = q//; t::lib::Mocks::mock_preference('ReservesNeedReturns', 1); # Somewhat arbitrary field chosen for age restriction unit tests. Must be added to db before the framework is cached -$dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestriction' where tagfield='521' and tagsubfield='a' and frameworkcode=?", undef, $frameworkcode); +$dbh->do(q| + INSERT INTO marc_subfield_structure (frameworkcode, tagfield, tagsubfield, kohafield) + VALUES ('', '521', 'a', 'biblioitems.agerestriction') + ON DUPLICATE KEY UPDATE kohafield = VALUES(kohafield) +|); my $cache = Koha::Caches->get_instance; $cache->clear_from_cache("MarcStructure-0-$frameworkcode"); $cache->clear_from_cache("MarcStructure-1-$frameworkcode"); -- 2.11.0