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

(-)a/t/db_dependent/Circulation.t (-22 / +148 lines)
Lines 2847-2892 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { Link Here
2847
};
2847
};
2848
2848
2849
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
2849
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
2850
    plan tests => 6;
2850
    plan tests => 31;
2851
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
2851
2852
2852
    my $homebranch  = $builder->build( { source => 'Branch' } );
2853
    my $homebranch    = $builder->build( { source => 'Branch' } );
2853
    my $otherbranch = $builder->build( { source => 'Branch' } );
2854
    my $holdingbranch = $builder->build( { source => 'Branch' } );
2854
    my $patron =
2855
    my $returnbranch  = $builder->build( { source => 'Branch' } );
2855
        $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
2856
    my $patron        = $builder->build_object(
2857
        { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } );
2856
2858
2857
    my $item = $builder->build_sample_item(
2859
    my $item = $builder->build_sample_item(
2858
        {
2860
        {
2859
            homebranch    => $homebranch->{branchcode},
2861
            homebranch    => $homebranch->{branchcode},
2860
            holdingbranch => $homebranch->{branchcode},
2862
            holdingbranch => $holdingbranch->{branchcode},
2861
        }
2863
        }
2862
    );
2864
    );
2863
2865
2864
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2866
    # Issue from holdingbranch
2865
    set_userenv($homebranch);
2867
    set_userenv($holdingbranch);
2866
    my $issue = AddIssue( $patron, $item->barcode );
2868
    my $issue = AddIssue( $patron, $item->barcode );
2867
    my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $otherbranch );
2869
2868
    is( 1,     $allowed, 'with AllowReturnToBranch = anywhere and no limits return to other is allowed' );
2870
    # 'Anywhere' + BranchTransferLimits
2871
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2872
2873
    # Attempt return at returnbranch (No limits defined)
2874
    my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2875
    is( 1,     $allowed, 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed' );
2869
    is( undef, $message, 'without limits provides no message' );
2876
    is( undef, $message, 'without limits provides no message' );
2870
2877
2871
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '1' );
2878
    # Set limit (Holding -> Return denied)
2872
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
2879
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
2873
2874
    # set limit
2875
    my $limit = Koha::Item::Transfer::Limit->new(
2880
    my $limit = Koha::Item::Transfer::Limit->new(
2876
        {
2881
        {
2877
            toBranch   => $otherbranch->{branchcode},
2882
            toBranch   => $returnbranch->{branchcode},
2878
            fromBranch => $item->homebranch,
2883
            fromBranch => $holdingbranch->{branchcode},
2879
            itemtype   => $item->effective_itemtype,
2884
            itemtype   => $item->effective_itemtype,
2880
        }
2885
        }
2881
    )->store();
2886
    )->store();
2882
2887
2883
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $otherbranch );
2888
    diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)");
2884
    is( 0,                         $allowed, 'With transfer limits cannot return to otherbranch' );
2889
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2885
    is( $homebranch->{branchcode}, $message, 'With transfer limits asks return to homebranch' );
2890
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2891
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch' );
2892
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2893
2894
    diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)");
2895
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2896
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2897
    is( 0,                            $allowed, 'Prevent return where returnbranch != holdingbranch' );
2898
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2899
2900
    diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)");
2901
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2902
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2903
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' );
2904
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2905
2906
    diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)");
2907
2908
    # NOTE: This prevents receiving an item from a branch that is listed in
2909
    # the branchtransferlimits as not allowed to send to our returnbranch.
2910
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2911
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2912
    is( 0, $allowed, 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch' );
2913
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2914
2915
    # Set limit ( Return -> Home denied)
2916
    $limit->set(
2917
        {
2918
            toBranch   => $homebranch->{branchcode},
2919
            fromBranch => $returnbranch->{branchcode}
2920
        }
2921
    )->store()->discard_changes;
2922
2923
    diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)");
2924
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2925
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2926
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch' );
2927
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2928
2929
    diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)");
2930
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2931
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2932
    is( 0,                            $allowed, 'Prevent return where returnbranch != holdingbranch' );
2933
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2934
2935
    diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)");
2936
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2937
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2938
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' );
2939
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2940
2941
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)");
2942
2943
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2944
    # to 'homebranch' (But we can transfer back to 'holdingbranch').
2945
    # NOTE: This is the ONLY change that bug 7376 introduces currently.
2946
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2947
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2948
    is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' );
2949
2950
    # Set limit ( Return -> Holding denied)
2951
    $limit->set(
2952
        {
2953
            toBranch   => $holdingbranch->{branchcode},
2954
            fromBranch => $returnbranch->{branchcode}
2955
        }
2956
    )->store()->discard_changes;
2957
2958
    diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)");
2959
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2960
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2961
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch' );
2962
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2963
2964
    diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)");
2965
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2966
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2967
    is( 0,                            $allowed, 'Prevent return where returnbranch != holdingbranch' );
2968
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2969
2970
    diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)");
2971
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2972
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2973
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' );
2974
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2886
2975
2887
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $homebranch );
2976
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)");
2888
    is( 1,     $allowed, 'With transfer limits can return to homebranch' );
2977
2889
    is( undef, $message, 'With transfer limits and homebranch provides no message' );
2978
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2979
    # to 'holdingbranch' (But we can transfer back to 'homebranch').
2980
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2981
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2982
    is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' );
2983
2984
    # Set limit ( Holding -> Home denied)
2985
    $limit->set(
2986
        {
2987
            toBranch   => $holdingbranch->{branchcode},
2988
            fromBranch => $returnbranch->{branchcode}
2989
        }
2990
    )->store()->discard_changes;
2991
2992
    diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)");
2993
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2994
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2995
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch' );
2996
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2997
2998
    diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)");
2999
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
3000
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
3001
    is( 0,                            $allowed, 'Prevent return where returnbranch != holdingbranch' );
3002
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
3003
3004
    diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)");
3005
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
3006
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
3007
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' );
3008
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
3009
3010
    diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)");
3011
3012
    # NOTE: A return here can subsequently be transfered to back to homebranch
3013
    # or holdingbranch.
3014
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
3015
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
3016
    is( 1, $allowed, 'Allow return where returnbranch can be transfered to from anywhere' );
2890
};
3017
};
2891
3018
2892
subtest 'Statistic patrons "X"' => sub {
3019
subtest 'Statistic patrons "X"' => sub {
2893
- 

Return to bug 7376