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

(-)a/C4/Reserves.pm (-5 / +19 lines)
Lines 265-271 sub AddReserve { Link Here
265
265
266
=head2 CanBookBeReserved
266
=head2 CanBookBeReserved
267
267
268
  $canReserve = &CanBookBeReserved($borrowernumber, $biblionumber)
268
  $canReserve = &CanBookBeReserved($borrowernumber, $biblionumber, $branchcode)
269
  if ($canReserve eq 'OK') { #We can reserve this Item! }
269
  if ($canReserve eq 'OK') { #We can reserve this Item! }
270
270
271
See CanItemBeReserved() for possible return values.
271
See CanItemBeReserved() for possible return values.
Lines 273-279 See CanItemBeReserved() for possible return values. Link Here
273
=cut
273
=cut
274
274
275
sub CanBookBeReserved{
275
sub CanBookBeReserved{
276
    my ($borrowernumber, $biblionumber) = @_;
276
    my ($borrowernumber, $biblionumber, $branchcode) = @_;
277
277
278
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
278
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
279
    #get items linked via host records
279
    #get items linked via host records
Lines 284-290 sub CanBookBeReserved{ Link Here
284
284
285
    my $canReserve;
285
    my $canReserve;
286
    foreach my $itemnumber (@itemnumbers) {
286
    foreach my $itemnumber (@itemnumbers) {
287
        $canReserve = CanItemBeReserved( $borrowernumber, $itemnumber );
287
        $canReserve = CanItemBeReserved( $borrowernumber, $itemnumber, $branchcode );
288
        return $canReserve if $canReserve->{status} eq 'OK';
288
        return $canReserve if $canReserve->{status} eq 'OK';
289
    }
289
    }
290
    return $canReserve;
290
    return $canReserve;
Lines 292-298 sub CanBookBeReserved{ Link Here
292
292
293
=head2 CanItemBeReserved
293
=head2 CanItemBeReserved
294
294
295
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber)
295
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber, $branchcode)
296
  if ($canReserve->{status} eq 'OK') { #We can reserve this Item! }
296
  if ($canReserve->{status} eq 'OK') { #We can reserve this Item! }
297
297
298
@RETURNS { status => OK },              if the Item can be reserved.
298
@RETURNS { status => OK },              if the Item can be reserved.
Lines 301-311 sub CanBookBeReserved{ Link Here
301
         { status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
301
         { status => cannotReserveFromOtherBranches }, if syspref 'canreservefromotherbranches' is OK.
302
         { status => tooManyReserves, limit => $limit }, if the borrower has exceeded their maximum reserve amount.
302
         { status => tooManyReserves, limit => $limit }, if the borrower has exceeded their maximum reserve amount.
303
         { status => notReservable },   if holds on this item are not allowed
303
         { status => notReservable },   if holds on this item are not allowed
304
         { status => libraryNotFound },   if given branchcode is not an existing library
305
         { status => libraryNotPickupLocation },   if given branchcode is not configured to be a pickup location
304
306
305
=cut
307
=cut
306
308
307
sub CanItemBeReserved {
309
sub CanItemBeReserved {
308
    my ( $borrowernumber, $itemnumber ) = @_;
310
    my ( $borrowernumber, $itemnumber, $branchcode_to ) = @_;
309
311
310
    my $dbh = C4::Context->dbh;
312
    my $dbh = C4::Context->dbh;
311
    my $ruleitemtype;    # itemtype of the matching issuing rule
313
    my $ruleitemtype;    # itemtype of the matching issuing rule
Lines 458-463 sub CanItemBeReserved { Link Here
458
        }
460
        }
459
    }
461
    }
460
462
463
    if ($branchcode_to) {
464
        my $destination = Koha::Libraries->find({
465
            branchcode => $branchcode_to,
466
        });
467
        unless ($destination) {
468
            return { status => 'libraryNotFound' };
469
        }
470
        unless ($destination->pickup_location) {
471
            return { status => 'libraryNotPickupLocation' };
472
        }
473
    }
474
461
    return { status => 'OK' };
475
    return { status => 'OK' };
462
}
476
}
463
477
(-)a/t/db_dependent/Holds.t (-2 / +26 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 => 55;
10
use Test::More tests => 62;
11
use MARC::Record;
11
use MARC::Record;
12
use Koha::Patrons;
12
use Koha::Patrons;
13
use C4::Items;
13
use C4::Items;
Lines 19-24 use Koha::Database; Link Here
19
use Koha::DateUtils qw( dt_from_string output_pref );
19
use Koha::DateUtils qw( dt_from_string output_pref );
20
use Koha::Biblios;
20
use Koha::Biblios;
21
use Koha::Holds;
21
use Koha::Holds;
22
use Koha::Items;
23
use Koha::Libraries;
22
24
23
BEGIN {
25
BEGIN {
24
    use FindBin;
26
    use FindBin;
Lines 479-484 subtest 'Test max_holds per library/patron category' => sub { Link Here
479
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
481
    is( $ret->{status}, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' );
480
};
482
};
481
483
484
subtest 'Pickup location availability tests' => sub {
485
    plan tests => 3;
486
487
    my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
488
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
489
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
490
    my $item = Koha::Items->find($itemnumber);
491
    my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
492
    my $library = Koha::Libraries->find($branch_to);
493
    my $patron = $builder->build({ source => 'Borrower' })->{ borrowernumber };
494
495
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
496
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
497
    $library->pickup_location('1')->store;
498
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
499
       'OK', 'Library is a pickup location');
500
    $library->pickup_location('0')->store;
501
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
502
       'libraryNotPickupLocation', 'Library is not a pickup location');
503
    is(CanItemBeReserved($patron, $item->itemnumber, 'nonexistent'),
504
       'libraryNotFound', 'Cannot set unknown library as pickup location');
505
};
506
482
# Helper method to set up a Biblio.
507
# Helper method to set up a Biblio.
483
sub create_helper_biblio {
508
sub create_helper_biblio {
484
    my $itemtype = shift;
509
    my $itemtype = shift;
485
- 

Return to bug 7534