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

(-)a/t/db_dependent/Circulation.t (-121 / +46 lines)
Lines 2601-2608 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { Link Here
2601
};
2601
};
2602
2602
2603
2603
2604
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
2604
subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub {
2605
    plan tests => 33;
2605
    plan tests => 22;
2606
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
2606
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
2607
2607
2608
    my $homebranch    = $builder->build( { source => 'Branch' } );
2608
    my $homebranch    = $builder->build( { source => 'Branch' } );
Lines 2621-2751 subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { Link Here
2621
    set_userenv($holdingbranch);
2621
    set_userenv($holdingbranch);
2622
    my $issue = AddIssue( $patron, $item->barcode );
2622
    my $issue = AddIssue( $patron, $item->barcode );
2623
2623
2624
    # 'Anywhere' + BranchTransferLimits
2624
    # Attempt returns at returnbranch
2625
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2626
2627
    # Attempt return at returnbranch (No limits defined)
2628
    my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2629
    is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed');
2630
    is ( undef , $message , 'without limits provides no message');
2631
2632
    # Set limit (Holding -> Return denied)
2633
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
2634
    my $limit = Koha::Item::Transfer::Limit->new({
2635
        toBranch   => $returnbranch->{branchcode},
2636
        fromBranch => $holdingbranch->{branchcode},
2637
        itemtype   => $item->effective_itemtype,
2638
    })->store();
2639
2640
    diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)");
2641
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2625
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2642
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2626
    my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2643
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2627
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2644
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2628
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2645
2629
2646
    diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)");
2647
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2630
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2648
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2631
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2649
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2632
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2650
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2633
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2651
2634
2652
    diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)");
2653
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2635
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2654
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2636
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2655
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2637
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2656
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2638
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2657
2639
2658
    diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)");
2659
    # NOTE: This prevents receiving an item from a branch that is listed in
2660
    # the branchtransferlimits as not allowed to send to our returnbranch.
2661
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2640
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2662
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2641
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2663
    is ( 0 , $allowed , 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch');
2642
    is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed');
2664
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2643
    is ( undef , $message , 'without limits provides no message');
2665
2666
    # Set limit ( Return -> Home denied)
2667
    $limit->set(
2668
        {
2669
            toBranch   => $homebranch->{branchcode},
2670
            fromBranch => $returnbranch->{branchcode}
2671
        }
2672
    )->store()->discard_changes;
2673
2674
    diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)");
2675
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2676
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2677
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2678
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2679
2680
    diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)");
2681
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2682
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2683
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2684
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2685
2686
    diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)");
2687
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2688
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2689
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2690
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2691
2692
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)");
2693
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2694
    # to 'homebranch' (But we can transfer back to 'holdingbranch').
2695
    # NOTE: This is the ONLY change that bug 7376 introduces currently.
2696
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2697
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2698
    is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to holding (homebranch forbidden) from returnbranch');
2699
2644
2700
    my $limit_2 = Koha::Item::Transfer::Limit->new({
2645
    # Set limit (Holding -> Return denied)
2701
        toBranch   => $holdingbranch->{branchcode},
2646
    diag("Transfer limit: Holding -> Return");
2702
        fromBranch => $returnbranch->{branchcode},
2647
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
2648
    my $limit = Koha::Item::Transfer::Limit->new({
2649
        toBranch   => $returnbranch->{branchcode},
2650
        fromBranch => $holdingbranch->{branchcode},
2703
        itemtype   => $item->effective_itemtype,
2651
        itemtype   => $item->effective_itemtype,
2704
    })->store();
2652
    })->store();
2705
2653
2706
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Home and Return -> Holding limit)");
2707
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2708
    # to 'homebranch' (But we can transfer back to 'holdingbranch').
2709
    # NOTE: This is the ONLY change that bug 7376 introduces currently.
2710
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2654
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2711
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2655
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2712
    is ( 0 , $allowed , 'Prevent return where item can\'t be transferred to both homebranch and holding from returnbranch');
2656
    is ( 1 , $allowed , 'Allow return where transferbranch is not passed');
2713
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2657
    is ( undef , $message , 'without limits provides no message');
2658
2659
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2660
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode});
2661
    is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and homebranch');
2662
    is ( undef , $message , 'without limits provides no message');
2714
2663
2715
    $limit_2->delete()->store()->discard_changes;
2664
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2665
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode});
2666
    is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and holdingbranch');
2667
    is ( undef , $message , 'without limits provides no message');
2716
2668
2717
    # Set limit ( Return -> Holding denied)
2669
    # Set limit ( Return -> Home denied)
2670
    diag("Transfer limit: Return -> Home");
2718
    $limit->set(
2671
    $limit->set(
2719
        {
2672
        {
2720
            toBranch   => $holdingbranch->{branchcode},
2673
            toBranch   => $homebranch->{branchcode},
2721
            fromBranch => $returnbranch->{branchcode}
2674
            fromBranch => $returnbranch->{branchcode}
2722
        }
2675
        }
2723
    )->store()->discard_changes;
2676
    )->store()->discard_changes;
2724
2677
2725
    diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)");
2678
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2726
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2679
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode});
2727
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2680
    is ( 0 , $allowed , 'Prevent return where returnbranch cannot transfer to homebranch');
2728
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2729
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2730
2731
    diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)");
2732
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2733
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2734
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2735
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2736
2737
    diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)");
2738
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2739
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2740
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2741
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2681
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2742
2682
2743
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)");
2744
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2745
    # to 'holdingbranch' (But we can transfer back to 'homebranch').
2746
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2683
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2747
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2684
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode});
2748
    is ( 1 , $allowed , 'Allow return where returnbranch can be transferred to homebranch (holdingbranch forbidden) from returnbranch');
2685
    is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and holdingbranch');
2686
    is ( undef , $message , 'without limits provides no message');
2687
 
2688
    # Set limit ( Return -> Holding denied)
2689
    diag("Transfer limit: Return -> Holding");
2749
2690
2750
    # Set limit ( Holding -> Home denied)
2691
    # Set limit ( Holding -> Home denied)
2751
    $limit->set(
2692
    $limit->set(
Lines 2755-2784 subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { Link Here
2755
        }
2696
        }
2756
    )->store()->discard_changes;
2697
    )->store()->discard_changes;
2757
2698
2758
    diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)");
2699
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2759
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2700
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode});
2760
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2701
    is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and homebranch');
2761
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2702
    is ( undef , $message , 'without limits provides no message');
2762
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2763
2764
    diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)");
2765
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2766
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2767
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2768
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2769
2770
    diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)");
2771
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2772
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2773
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2774
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2775
2703
2776
    diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)");
2777
    # NOTE: A return here can subsequently be transferred to back to homebranch
2778
    # or holdingbranch.
2779
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2704
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2780
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2705
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode});
2781
    is ( 1 , $allowed , 'Allow return where returnbranch can be transferred to from anywhere');
2706
    is ( 0 , $allowed , 'Prevent return where returnbranch cannot transfer to holdingbranch');
2707
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2782
};
2708
};
2783
2709
2784
2710
2785
- 

Return to bug 7376