View | Details | Raw Unified | Return to bug 7614
Collapse All | Expand All

(-)a/C4/Reserves.pm (-5 / +23 lines)
Lines 418-424 sub GetReservesFromBorrowernumber { Link Here
418
418
419
=head2 CanBookBeReserved
419
=head2 CanBookBeReserved
420
420
421
  $canReserve = &CanBookBeReserved($borrowernumber, $biblionumber)
421
  $canReserve = &CanBookBeReserved($borrowernumber, $biblionumber, $branchcode)
422
  if ($canReserve eq 'OK') { #We can reserve this Item! }
422
  if ($canReserve eq 'OK') { #We can reserve this Item! }
423
423
424
See CanItemBeReserved() for possible return values.
424
See CanItemBeReserved() for possible return values.
Lines 426-432 See CanItemBeReserved() for possible return values. Link Here
426
=cut
426
=cut
427
427
428
sub CanBookBeReserved{
428
sub CanBookBeReserved{
429
    my ($borrowernumber, $biblionumber) = @_;
429
    my ($borrowernumber, $biblionumber, $branchcode) = @_;
430
430
431
    my $items = GetItemnumbersForBiblio($biblionumber);
431
    my $items = GetItemnumbersForBiblio($biblionumber);
432
    #get items linked via host records
432
    #get items linked via host records
Lines 437-443 sub CanBookBeReserved{ Link Here
437
437
438
    my $canReserve;
438
    my $canReserve;
439
    foreach my $item (@$items) {
439
    foreach my $item (@$items) {
440
        $canReserve = CanItemBeReserved( $borrowernumber, $item );
440
        $canReserve = CanItemBeReserved( $borrowernumber, $item, $branchcode );
441
        return 'OK' if $canReserve eq 'OK';
441
        return 'OK' if $canReserve eq 'OK';
442
    }
442
    }
443
    return $canReserve;
443
    return $canReserve;
Lines 445-451 sub CanBookBeReserved{ Link Here
445
445
446
=head2 CanItemBeReserved
446
=head2 CanItemBeReserved
447
447
448
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber)
448
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber, $branchcode)
449
  if ($canReserve eq 'OK') { #We can reserve this Item! }
449
  if ($canReserve eq 'OK') { #We can reserve this Item! }
450
450
451
@RETURNS OK,              if the Item can be reserved.
451
@RETURNS OK,              if the Item can be reserved.
Lines 454-464 sub CanBookBeReserved{ Link Here
454
         cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK.
454
         cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK.
455
         tooManyReserves, if the borrower has exceeded his maximum reserve amount.
455
         tooManyReserves, if the borrower has exceeded his maximum reserve amount.
456
         notReservable,   if holds on this item are not allowed
456
         notReservable,   if holds on this item are not allowed
457
         libraryNotFound  if given branchcode is not an existing library
458
         libraryNotPickupLocation if given branchcode is not configured to be a pickup location
459
         cannotBeTransferred if branch transfer limit applies on given item and branchcode
457
460
458
=cut
461
=cut
459
462
460
sub CanItemBeReserved {
463
sub CanItemBeReserved {
461
    my ( $borrowernumber, $itemnumber ) = @_;
464
    my ( $borrowernumber, $itemnumber, $branchcode_to ) = @_;
462
465
463
    my $dbh = C4::Context->dbh;
466
    my $dbh = C4::Context->dbh;
464
    my $ruleitemtype;    # itemtype of the matching issuing rule
467
    my $ruleitemtype;    # itemtype of the matching issuing rule
Lines 587-592 sub CanItemBeReserved { Link Here
587
        }
590
        }
588
    }
591
    }
589
592
593
    if ($branchcode_to) {
594
        my $destination = Koha::Libraries->find({
595
            branchcode => $branchcode_to,
596
        });
597
        unless ($destination) {
598
            return 'libraryNotFound';
599
        }
600
        unless ($destination->pickup_location) {
601
            return 'libraryNotPickupLocation';
602
        }
603
        unless ($item->can_be_transferred({ to => $destination->branchcode })) {
604
            return 'cannotBeTransferred';
605
        }
606
    }
607
590
    return 'OK';
608
    return 'OK';
591
}
609
}
592
610
(-)a/t/db_dependent/Holds.t (-1 / +32 lines)
Lines 16-21 use C4::Calendar; Link Here
16
use Koha::Database;
16
use Koha::Database;
17
use Koha::DateUtils qw( dt_from_string output_pref );
17
use Koha::DateUtils qw( dt_from_string output_pref );
18
use Koha::Holds;
18
use Koha::Holds;
19
use Koha::Item::Transfer::Limits;
20
use Koha::Items;
21
use Koha::Libraries;
19
22
20
BEGIN {
23
BEGIN {
21
    use FindBin;
24
    use FindBin;
Lines 485-491 my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); Link Here
485
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
488
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
486
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
489
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
487
490
491
subtest 'Pickup location availability tests' => sub {
492
    plan tests => 3;
488
493
494
    my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
495
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
496
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
497
    my $item = Koha::Items->find($itemnumber);
498
    my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
499
    my $library = Koha::Libraries->find($branch_to);
500
    $library->pickup_location('1')->store;
501
    my $patron = $builder->build({ source => 'Borrower' })->{ borrowernumber };
502
503
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
504
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
505
506
    my $limit = Koha::Item::Transfer::Limit->new({
507
        fromBranch => $item->holdingbranch,
508
        toBranch => $branch_to,
509
        itemtype => $item->effective_itemtype,
510
    })->store;
511
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
512
       'cannotBeTransferred', 'Item cannot be transferred');
513
    $limit->delete;
514
    $library->pickup_location('0')->store;
515
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
516
       'libraryNotPickupLocation', 'Library is not a pickup location');
517
    is(CanItemBeReserved($patron, $item->itemnumber, 'nonexistent'),
518
       'libraryNotFound', 'Cannot set unknown library as pickup location');
519
};
520
my ( $bibnum, $title, $bibitemnum );
489
# Helper method to set up a Biblio.
521
# Helper method to set up a Biblio.
490
sub create_helper_biblio {
522
sub create_helper_biblio {
491
    my $itemtype = shift;
523
    my $itemtype = shift;
492
- 

Return to bug 7614