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

(-)a/C4/Reserves.pm (-5 / +19 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
457
459
458
=cut
460
=cut
459
461
460
sub CanItemBeReserved {
462
sub CanItemBeReserved {
461
    my ( $borrowernumber, $itemnumber ) = @_;
463
    my ( $borrowernumber, $itemnumber, $branchcode_to ) = @_;
462
464
463
    my $dbh = C4::Context->dbh;
465
    my $dbh = C4::Context->dbh;
464
    my $ruleitemtype;    # itemtype of the matching issuing rule
466
    my $ruleitemtype;    # itemtype of the matching issuing rule
Lines 587-592 sub CanItemBeReserved { Link Here
587
        }
589
        }
588
    }
590
    }
589
591
592
    if ($branchcode_to) {
593
        my $destination = Koha::Libraries->find({
594
            branchcode => $branchcode_to,
595
        });
596
        unless ($destination) {
597
            return 'libraryNotFound';
598
        }
599
        unless ($destination->pickup_location) {
600
            return 'libraryNotPickupLocation';
601
        }
602
    }
603
590
    return 'OK';
604
    return 'OK';
591
}
605
}
592
606
(-)a/t/db_dependent/Holds.t (-2 / +25 lines)
Lines 7-13 use t::lib::TestBuilder; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
9
10
use Test::More tests => 61;
10
use Test::More tests => 62;
11
use MARC::Record;
11
use MARC::Record;
12
use C4::Biblio;
12
use C4::Biblio;
13
use C4::Items;
13
use C4::Items;
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::Items;
20
use Koha::Libraries;
19
21
20
BEGIN {
22
BEGIN {
21
    use FindBin;
23
    use FindBin;
Lines 485-491 my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); Link Here
485
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
487
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
486
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
488
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
487
489
490
subtest 'Pickup location availability tests' => sub {
491
    plan tests => 3;
488
492
493
    my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
494
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
495
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
496
    my $item = Koha::Items->find($itemnumber);
497
    my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
498
    my $library = Koha::Libraries->find($branch_to);
499
    my $patron = $builder->build({ source => 'Borrower' })->{ borrowernumber };
500
501
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
502
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
503
    $library->pickup_location('1')->store;
504
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
505
       'OK', 'Library is a pickup location');
506
    $library->pickup_location('0')->store;
507
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
508
       'libraryNotPickupLocation', 'Library is not a pickup location');
509
    is(CanItemBeReserved($patron, $item->itemnumber, 'nonexistent'),
510
       'libraryNotFound', 'Cannot set unknown library as pickup location');
511
};
512
my ( $bibnum, $title, $bibitemnum );
489
# Helper method to set up a Biblio.
513
# Helper method to set up a Biblio.
490
sub create_helper_biblio {
514
sub create_helper_biblio {
491
    my $itemtype = shift;
515
    my $itemtype = shift;
492
- 

Return to bug 7534