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

(-)a/t/db_dependent/Circulation.t (-136 / +51 lines)
Lines 2846-2853 subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub { Link Here
2846
    );
2846
    );
2847
};
2847
};
2848
2848
2849
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
2849
subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub {
2850
    plan tests => 33;
2850
    plan tests => 22;
2851
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
2851
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
2852
2852
2853
    my $homebranch    = $builder->build( { source => 'Branch' } );
2853
    my $homebranch    = $builder->build( { source => 'Branch' } );
Lines 2867-3014 subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { Link Here
2867
    set_userenv($holdingbranch);
2867
    set_userenv($holdingbranch);
2868
    my $issue = AddIssue( $patron, $item->barcode );
2868
    my $issue = AddIssue( $patron, $item->barcode );
2869
2869
2870
    # 'Anywhere' + BranchTransferLimits
2870
    # Attempt returns at returnbranch
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' );
2876
    is( undef, $message, 'without limits provides no message' );
2877
2878
    # Set limit (Holding -> Return denied)
2879
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
2880
    my $limit = Koha::Item::Transfer::Limit->new(
2881
        {
2882
            toBranch   => $returnbranch->{branchcode},
2883
            fromBranch => $holdingbranch->{branchcode},
2884
            itemtype   => $item->effective_itemtype,
2885
        }
2886
    )->store();
2887
2888
    diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)");
2889
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2871
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2890
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2872
    my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} );
2891
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch' );
2873
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch' );
2892
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2874
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2893
2875
2894
    diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)");
2895
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2876
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2896
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2877
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} );
2897
    is( 0,                            $allowed, 'Prevent return where returnbranch != holdingbranch' );
2878
    is( 0,                            $allowed, 'Prevent return where returnbranch != holdingbranch' );
2898
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2879
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2899
2880
2900
    diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)");
2901
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2881
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2902
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2882
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} );
2903
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' );
2883
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' );
2904
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2884
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2905
2885
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' );
2886
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2911
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2887
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} );
2912
    is( 0, $allowed, 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch' );
2888
    is( 1,     $allowed, 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed' );
2913
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2889
    is( undef, $message, 'without limits provides no message' );
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(
2949
        1, $allowed,
2950
        'Allow return where returnbranch can be transfered to holding (homebranch forbidden) from returnbranch'
2951
    );
2952
2890
2953
    my $limit_2 = Koha::Item::Transfer::Limit->new(
2891
    # Set limit (Holding -> Return denied)
2892
    diag("Transfer limit: Holding -> Return");
2893
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
2894
    my $limit = Koha::Item::Transfer::Limit->new(
2954
        {
2895
        {
2955
            toBranch   => $holdingbranch->{branchcode},
2896
            toBranch   => $returnbranch->{branchcode},
2956
            fromBranch => $returnbranch->{branchcode},
2897
            fromBranch => $holdingbranch->{branchcode},
2957
            itemtype   => $item->effective_itemtype,
2898
            itemtype   => $item->effective_itemtype,
2958
        }
2899
        }
2959
    )->store();
2900
    )->store();
2960
2901
2961
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Home and Return -> Holding limit)");
2902
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2903
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} );
2904
    is( 1,     $allowed, 'Allow return where transferbranch is not passed' );
2905
    is( undef, $message, 'without limits provides no message' );
2962
2906
2963
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2964
    # to 'homebranch' (But we can transfer back to 'holdingbranch').
2965
    # NOTE: This is the ONLY change that bug 7376 introduces currently.
2966
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2907
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2967
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2908
    ( $allowed, $message ) =
2968
    is(
2909
        C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $homebranch->{branchcode} );
2969
        0, $allowed,
2910
    is( 1,     $allowed, 'Allow return where there is no transfer limit between returnbranch and homebranch' );
2970
        'Prevent return where item can\'t be transferred to both homebranch and holding from returnbranch'
2911
    is( undef, $message, 'without limits provides no message' );
2971
    );
2972
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2973
2912
2974
    $limit_2->delete()->store()->discard_changes;
2913
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2914
    ( $allowed, $message ) =
2915
        C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $holdingbranch->{branchcode} );
2916
    is( 1,     $allowed, 'Allow return where there is no transfer limit between returnbranch and holdingbranch' );
2917
    is( undef, $message, 'without limits provides no message' );
2975
2918
2976
    # Set limit ( Return -> Holding denied)
2919
    # Set limit ( Return -> Home denied)
2920
    diag("Transfer limit: Return -> Home");
2977
    $limit->set(
2921
    $limit->set(
2978
        {
2922
        {
2979
            toBranch   => $holdingbranch->{branchcode},
2923
            toBranch   => $homebranch->{branchcode},
2980
            fromBranch => $returnbranch->{branchcode}
2924
            fromBranch => $returnbranch->{branchcode}
2981
        }
2925
        }
2982
    )->store()->discard_changes;
2926
    )->store()->discard_changes;
2983
2927
2984
    diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)");
2928
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2985
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2929
    ( $allowed, $message ) =
2986
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2930
        C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $homebranch->{branchcode} );
2987
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch' );
2931
    is( 0,                         $allowed, 'Prevent return where returnbranch cannot transfer to homebranch' );
2988
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2989
2990
    diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)");
2991
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2992
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2993
    is( 0,                            $allowed, 'Prevent return where returnbranch != holdingbranch' );
2994
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
2995
2996
    diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)");
2997
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2998
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2999
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' );
3000
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2932
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
3001
2933
3002
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)");
3003
3004
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
3005
    # to 'holdingbranch' (But we can transfer back to 'homebranch').
3006
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2934
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
3007
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2935
    ( $allowed, $message ) =
3008
    is(
2936
        C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $holdingbranch->{branchcode} );
3009
        1, $allowed,
2937
    is( 1,     $allowed, 'Allow return where there is no transfer limit between returnbranch and holdingbranch' );
3010
        'Allow return where returnbranch can be transferred to homebranch (holdingbranch forbidden) from returnbranch'
2938
    is( undef, $message, 'without limits provides no message' );
3011
    );
2939
2940
    # Set limit ( Return -> Holding denied)
2941
    diag("Transfer limit: Return -> Holding");
3012
2942
3013
    # Set limit ( Holding -> Home denied)
2943
    # Set limit ( Holding -> Home denied)
3014
    $limit->set(
2944
    $limit->set(
Lines 3018-3048 subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { Link Here
3018
        }
2948
        }
3019
    )->store()->discard_changes;
2949
    )->store()->discard_changes;
3020
2950
3021
    diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)");
2951
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
3022
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2952
    ( $allowed, $message ) =
3023
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2953
        C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $homebranch->{branchcode} );
3024
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch' );
2954
    is( 1,     $allowed, 'Allow return where there is no transfer limit between returnbranch and homebranch' );
3025
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
2955
    is( undef, $message, 'without limits provides no message' );
3026
3027
    diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)");
3028
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
3029
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
3030
    is( 0,                            $allowed, 'Prevent return where returnbranch != holdingbranch' );
3031
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
3032
3033
    diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)");
3034
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
3035
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
3036
    is( 0,                         $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' );
3037
    is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' );
3038
3039
    diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)");
3040
2956
3041
    # NOTE: A return here can subsequently be transferred to back to homebranch
3042
    # or holdingbranch.
3043
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2957
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
3044
    ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch );
2958
    ( $allowed, $message ) =
3045
    is( 1, $allowed, 'Allow return where returnbranch can be transferred to from anywhere' );
2959
        C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $holdingbranch->{branchcode} );
2960
    is( 0,                            $allowed, 'Prevent return where returnbranch cannot transfer to holdingbranch' );
2961
    is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' );
3046
};
2962
};
3047
2963
3048
subtest 'Statistic patrons "X"' => sub {
2964
subtest 'Statistic patrons "X"' => sub {
3049
- 

Return to bug 7376