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