Browse Source

Bug 7614: Check transfer limit in CanBookBeReserved and CanItemBeReserved

This patch adds $branchcode_to parameter to CanBookBeReserved and
CanItemBeReserved. It represents the pickup location for the hold. This patch
checks if the library is configured to be a pickup location (see Bug 7534), and
also if the item can be transferred into the given library (see Bug 18072).

To test:
1. prove t/db_dependent/Holds.t

Signed-off-by: Bob Bennhoff <bbennhoff@clicweb.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
19.05.x
Lari Taskula 6 years ago
committed by Nick Clemens
parent
commit
b028a2d1a5
  1. 16
      C4/Reserves.pm
  2. 24
      t/db_dependent/Holds.t

16
C4/Reserves.pm

@ -297,6 +297,7 @@ sub CanBookBeReserved{
$canReserve = &CanItemBeReserved($borrowernumber, $itemnumber, $branchcode)
if ($canReserve->{status} eq 'OK') { #We can reserve this Item! }
<<<<<<< HEAD
@RETURNS { status => OK }, if the Item can be reserved.
{ status => ageRestricted }, if the Item is age restricted for this borrower.
{ status => damaged }, if the Item is damaged.
@ -305,6 +306,17 @@ sub CanBookBeReserved{
{ status => notReservable }, if holds on this item are not allowed
{ status => libraryNotFound }, if given branchcode is not an existing library
{ status => libraryNotPickupLocation }, if given branchcode is not configured to be a pickup location
=======
@RETURNS OK, if the Item can be reserved.
ageRestricted, if the Item is age restricted for this borrower.
damaged, if the Item is damaged.
cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK.
tooManyReserves, if the borrower has exceeded his maximum reserve amount.
notReservable, if holds on this item are not allowed
libraryNotFound if given branchcode is not an existing library
libraryNotPickupLocation if given branchcode is not configured to be a pickup location
cannotBeTransferred if branch transfer limit applies on given item and branchcode
>>>>>>> Bug 7614: Check transfer limit in CanBookBeReserved and CanItemBeReserved
=cut
@ -475,12 +487,16 @@ sub CanItemBeReserved {
my $destination = Koha::Libraries->find({
branchcode => $pickup_branchcode,
});
unless ($destination) {
return { status => 'libraryNotFound' };
}
unless ($destination->pickup_location) {
return { status => 'libraryNotPickupLocation' };
}
unless ($item->can_be_transferred({ to => $destination })) {
return 'cannotBeTransferred';
}
}
return { status => 'OK' };

24
t/db_dependent/Holds.t

@ -9,17 +9,19 @@ use C4::Context;
use Test::More tests => 57;
use MARC::Record;
use C4::Items;
use C4::Biblio;
use C4::Reserves;
use C4::Calendar;
use C4::Items;
use C4::Reserves;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Biblios;
use Koha::CirculationRules;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Holds;
use Koha::IssuingRules;
use Koha::Item::Transfer::Limits;
use Koha::Items;
use Koha::Libraries;
use Koha::Patrons;
@ -490,7 +492,7 @@ subtest 'Test max_holds per library/patron category' => sub {
};
subtest 'Pickup location availability tests' => sub {
plan tests => 3;
plan tests => 4;
my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
my ( $item_bibnum, $item_bibitemnum, $itemnumber )
@ -505,13 +507,25 @@ subtest 'Pickup location availability tests' => sub {
my $item = Koha::Items->find($itemnumber);
my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
my $library = Koha::Libraries->find($branch_to);
$library->pickup_location('1')->store;
my $patron = $builder->build({ source => 'Borrower' })->{ borrowernumber };
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
$library->pickup_location('1')->store;
is(CanItemBeReserved($patron, $item->itemnumber, $branch_to)->{status},
'OK', 'Library is a pickup location');
my $limit = Koha::Item::Transfer::Limit->new({
fromBranch => $item->holdingbranch,
toBranch => $branch_to,
itemtype => $item->effective_itemtype,
})->store;
is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
'cannotBeTransferred', 'Item cannot be transferred');
$limit->delete;
$library->pickup_location('0')->store;
is(CanItemBeReserved($patron, $item->itemnumber, $branch_to)->{status},
'libraryNotPickupLocation', 'Library is not a pickup location');

Loading…
Cancel
Save