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 $items = GetItemnumbersForBiblio($biblionumber);
278
    my $items = GetItemnumbersForBiblio($biblionumber);
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 $item (@$items) {
286
    foreach my $item (@$items) {
287
        $canReserve = CanItemBeReserved( $borrowernumber, $item );
287
        $canReserve = CanItemBeReserved( $borrowernumber, $item, $branchcode );
288
        return 'OK' if $canReserve eq 'OK';
288
        return 'OK' if $canReserve 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 eq 'OK') { #We can reserve this Item! }
296
  if ($canReserve eq 'OK') { #We can reserve this Item! }
297
297
298
@RETURNS OK,              if the Item can be reserved.
298
@RETURNS OK,              if the Item can be reserved.
Lines 301-311 sub CanBookBeReserved{ Link Here
301
         cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK.
301
         cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK.
302
         tooManyReserves, if the borrower has exceeded his maximum reserve amount.
302
         tooManyReserves, if the borrower has exceeded his maximum reserve amount.
303
         notReservable,   if holds on this item are not allowed
303
         notReservable,   if holds on this item are not allowed
304
         libraryNotFound  if given branchcode is not an existing library
305
         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 435-440 sub CanItemBeReserved { Link Here
435
        }
437
        }
436
    }
438
    }
437
439
440
    if ($branchcode_to) {
441
        my $destination = Koha::Libraries->find({
442
            branchcode => $branchcode_to,
443
        });
444
        unless ($destination) {
445
            return 'libraryNotFound';
446
        }
447
        unless ($destination->pickup_location) {
448
            return 'libraryNotPickupLocation';
449
        }
450
    }
451
438
    return 'OK';
452
    return 'OK';
439
}
453
}
440
454
(-)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 => 54;
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 411-416 my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); Link Here
411
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
413
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ),
412
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
414
    'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' );
413
415
416
subtest 'Pickup location availability tests' => sub {
417
    plan tests => 3;
418
419
    my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
420
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
421
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $bibnum );
422
    my $item = Koha::Items->find($itemnumber);
423
    my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
424
    my $library = Koha::Libraries->find($branch_to);
425
    my $patron = $builder->build({ source => 'Borrower' })->{ borrowernumber };
426
427
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
428
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
429
    $library->pickup_location('1')->store;
430
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
431
       'OK', 'Library is a pickup location');
432
    $library->pickup_location('0')->store;
433
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
434
       'libraryNotPickupLocation', 'Library is not a pickup location');
435
    is(CanItemBeReserved($patron, $item->itemnumber, 'nonexistent'),
436
       'libraryNotFound', 'Cannot set unknown library as pickup location');
437
};
414
438
415
# Helper method to set up a Biblio.
439
# Helper method to set up a Biblio.
416
sub create_helper_biblio {
440
sub create_helper_biblio {
417
- 

Return to bug 7534