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

(-)a/C4/Reserves.pm (+16 lines)
Lines 297-302 sub CanBookBeReserved{ Link Here
297
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber, $branchcode)
297
  $canReserve = &CanItemBeReserved($borrowernumber, $itemnumber, $branchcode)
298
  if ($canReserve->{status} eq 'OK') { #We can reserve this Item! }
298
  if ($canReserve->{status} eq 'OK') { #We can reserve this Item! }
299
299
300
<<<<<<< HEAD
300
@RETURNS { status => OK },              if the Item can be reserved.
301
@RETURNS { status => OK },              if the Item can be reserved.
301
         { status => ageRestricted },   if the Item is age restricted for this borrower.
302
         { status => ageRestricted },   if the Item is age restricted for this borrower.
302
         { status => damaged },         if the Item is damaged.
303
         { status => damaged },         if the Item is damaged.
Lines 305-310 sub CanBookBeReserved{ Link Here
305
         { status => notReservable },   if holds on this item are not allowed
306
         { status => notReservable },   if holds on this item are not allowed
306
         { status => libraryNotFound },   if given branchcode is not an existing library
307
         { status => libraryNotFound },   if given branchcode is not an existing library
307
         { status => libraryNotPickupLocation },   if given branchcode is not configured to be a pickup location
308
         { status => libraryNotPickupLocation },   if given branchcode is not configured to be a pickup location
309
=======
310
@RETURNS OK,              if the Item can be reserved.
311
         ageRestricted,   if the Item is age restricted for this borrower.
312
         damaged,         if the Item is damaged.
313
         cannotReserveFromOtherBranches, if syspref 'canreservefromotherbranches' is OK.
314
         tooManyReserves, if the borrower has exceeded his maximum reserve amount.
315
         notReservable,   if holds on this item are not allowed
316
         libraryNotFound  if given branchcode is not an existing library
317
         libraryNotPickupLocation if given branchcode is not configured to be a pickup location
318
         cannotBeTransferred if branch transfer limit applies on given item and branchcode
319
>>>>>>> Bug 7614: Check transfer limit in CanBookBeReserved and CanItemBeReserved
308
320
309
=cut
321
=cut
310
322
Lines 475-486 sub CanItemBeReserved { Link Here
475
        my $destination = Koha::Libraries->find({
487
        my $destination = Koha::Libraries->find({
476
            branchcode => $pickup_branchcode,
488
            branchcode => $pickup_branchcode,
477
        });
489
        });
490
478
        unless ($destination) {
491
        unless ($destination) {
479
            return { status => 'libraryNotFound' };
492
            return { status => 'libraryNotFound' };
480
        }
493
        }
481
        unless ($destination->pickup_location) {
494
        unless ($destination->pickup_location) {
482
            return { status => 'libraryNotPickupLocation' };
495
            return { status => 'libraryNotPickupLocation' };
483
        }
496
        }
497
        unless ($item->can_be_transferred({ to => $destination })) {
498
            return 'cannotBeTransferred';
499
        }
484
    }
500
    }
485
501
486
    return { status => 'OK' };
502
    return { status => 'OK' };
(-)a/t/db_dependent/Holds.t (-6 / +19 lines)
Lines 9-25 use C4::Context; Link Here
9
9
10
use Test::More tests => 57;
10
use Test::More tests => 57;
11
use MARC::Record;
11
use MARC::Record;
12
use C4::Items;
12
13
use C4::Biblio;
13
use C4::Biblio;
14
use C4::Reserves;
15
use C4::Calendar;
14
use C4::Calendar;
15
use C4::Items;
16
use C4::Reserves;
16
17
17
use Koha::Database;
18
use Koha::DateUtils qw( dt_from_string output_pref );
19
use Koha::Biblios;
18
use Koha::Biblios;
20
use Koha::CirculationRules;
19
use Koha::CirculationRules;
20
use Koha::Database;
21
use Koha::DateUtils qw( dt_from_string output_pref );
21
use Koha::Holds;
22
use Koha::Holds;
22
use Koha::IssuingRules;
23
use Koha::IssuingRules;
24
use Koha::Item::Transfer::Limits;
23
use Koha::Items;
25
use Koha::Items;
24
use Koha::Libraries;
26
use Koha::Libraries;
25
use Koha::Patrons;
27
use Koha::Patrons;
Lines 490-496 subtest 'Test max_holds per library/patron category' => sub { Link Here
490
};
492
};
491
493
492
subtest 'Pickup location availability tests' => sub {
494
subtest 'Pickup location availability tests' => sub {
493
    plan tests => 3;
495
    plan tests => 4;
494
496
495
    my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
497
    my ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('ONLY1');
496
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
498
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
Lines 505-517 subtest 'Pickup location availability tests' => sub { Link Here
505
    my $item = Koha::Items->find($itemnumber);
507
    my $item = Koha::Items->find($itemnumber);
506
    my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
508
    my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
507
    my $library = Koha::Libraries->find($branch_to);
509
    my $library = Koha::Libraries->find($branch_to);
510
    $library->pickup_location('1')->store;
508
    my $patron = $builder->build({ source => 'Borrower' })->{ borrowernumber };
511
    my $patron = $builder->build({ source => 'Borrower' })->{ borrowernumber };
509
512
510
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
513
    t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1);
511
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
514
    t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype');
515
512
    $library->pickup_location('1')->store;
516
    $library->pickup_location('1')->store;
513
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to)->{status},
517
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to)->{status},
514
       'OK', 'Library is a pickup location');
518
       'OK', 'Library is a pickup location');
519
520
    my $limit = Koha::Item::Transfer::Limit->new({
521
        fromBranch => $item->holdingbranch,
522
        toBranch => $branch_to,
523
        itemtype => $item->effective_itemtype,
524
    })->store;
525
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to),
526
       'cannotBeTransferred', 'Item cannot be transferred');
527
    $limit->delete;
528
515
    $library->pickup_location('0')->store;
529
    $library->pickup_location('0')->store;
516
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to)->{status},
530
    is(CanItemBeReserved($patron, $item->itemnumber, $branch_to)->{status},
517
       'libraryNotPickupLocation', 'Library is not a pickup location');
531
       'libraryNotPickupLocation', 'Library is not a pickup location');
518
- 

Return to bug 7614