|
Lines 2897-2904
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub {
Link Here
|
| 2897 |
); |
2897 |
); |
| 2898 |
}; |
2898 |
}; |
| 2899 |
|
2899 |
|
| 2900 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { |
2900 |
subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub { |
| 2901 |
plan tests => 33; |
2901 |
plan tests => 22; |
| 2902 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
2902 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
| 2903 |
|
2903 |
|
| 2904 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
2904 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
|
Lines 2918-3065
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
Link Here
|
| 2918 |
set_userenv($holdingbranch); |
2918 |
set_userenv($holdingbranch); |
| 2919 |
my $issue = AddIssue( $patron, $item->barcode ); |
2919 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 2920 |
|
2920 |
|
| 2921 |
# 'Anywhere' + BranchTransferLimits |
2921 |
# Attempt returns at returnbranch |
| 2922 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
|
|
| 2923 |
|
| 2924 |
# Attempt return at returnbranch (No limits defined) |
| 2925 |
my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2926 |
is( 1, $allowed, 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed' ); |
| 2927 |
is( undef, $message, 'without limits provides no message' ); |
| 2928 |
|
| 2929 |
# Set limit (Holding -> Return denied) |
| 2930 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 2931 |
my $limit = Koha::Item::Transfer::Limit->new( |
| 2932 |
{ |
| 2933 |
toBranch => $returnbranch->{branchcode}, |
| 2934 |
fromBranch => $holdingbranch->{branchcode}, |
| 2935 |
itemtype => $item->effective_itemtype, |
| 2936 |
} |
| 2937 |
)->store(); |
| 2938 |
|
| 2939 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)"); |
| 2940 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
2922 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2941 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
2923 |
my ( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} ); |
| 2942 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
2924 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 2943 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
2925 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2944 |
|
2926 |
|
| 2945 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)"); |
|
|
| 2946 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
2927 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2947 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
2928 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} ); |
| 2948 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
2929 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 2949 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
2930 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 2950 |
|
2931 |
|
| 2951 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)"); |
|
|
| 2952 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
2932 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2953 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
2933 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} ); |
| 2954 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
2934 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 2955 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
2935 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2956 |
|
2936 |
|
| 2957 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)"); |
|
|
| 2958 |
|
| 2959 |
# NOTE: This prevents receiving an item from a branch that is listed in |
| 2960 |
# the branchtransferlimits as not allowed to send to our returnbranch. |
| 2961 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2937 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2962 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
2938 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} ); |
| 2963 |
is( 0, $allowed, 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch' ); |
2939 |
is( 1, $allowed, 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed' ); |
| 2964 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
2940 |
is( undef, $message, 'without limits provides no message' ); |
| 2965 |
|
|
|
| 2966 |
# Set limit ( Return -> Home denied) |
| 2967 |
$limit->set( |
| 2968 |
{ |
| 2969 |
toBranch => $homebranch->{branchcode}, |
| 2970 |
fromBranch => $returnbranch->{branchcode} |
| 2971 |
} |
| 2972 |
)->store()->discard_changes; |
| 2973 |
|
| 2974 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)"); |
| 2975 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 2976 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2977 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
| 2978 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2979 |
|
| 2980 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)"); |
| 2981 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 2982 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2983 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 2984 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 2985 |
|
| 2986 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)"); |
| 2987 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 2988 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2989 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 2990 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 2991 |
|
| 2992 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)"); |
| 2993 |
|
| 2994 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 2995 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
| 2996 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
| 2997 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 2998 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 2999 |
is( |
| 3000 |
1, $allowed, |
| 3001 |
'Allow return where returnbranch can be transfered to holding (homebranch forbidden) from returnbranch' |
| 3002 |
); |
| 3003 |
|
2941 |
|
| 3004 |
my $limit_2 = Koha::Item::Transfer::Limit->new( |
2942 |
# Set limit (Holding -> Return denied) |
|
|
2943 |
diag("Transfer limit: Holding -> Return"); |
| 2944 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 2945 |
my $limit = Koha::Item::Transfer::Limit->new( |
| 3005 |
{ |
2946 |
{ |
| 3006 |
toBranch => $holdingbranch->{branchcode}, |
2947 |
toBranch => $returnbranch->{branchcode}, |
| 3007 |
fromBranch => $returnbranch->{branchcode}, |
2948 |
fromBranch => $holdingbranch->{branchcode}, |
| 3008 |
itemtype => $item->effective_itemtype, |
2949 |
itemtype => $item->effective_itemtype, |
| 3009 |
} |
2950 |
} |
| 3010 |
)->store(); |
2951 |
)->store(); |
| 3011 |
|
2952 |
|
| 3012 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Home and Return -> Holding limit)"); |
2953 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
|
|
2954 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode} ); |
| 2955 |
is( 1, $allowed, 'Allow return where transferbranch is not passed' ); |
| 2956 |
is( undef, $message, 'without limits provides no message' ); |
| 3013 |
|
2957 |
|
| 3014 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
|
|
| 3015 |
# to 'homebranch' (But we can transfer back to 'holdingbranch'). |
| 3016 |
# NOTE: This is the ONLY change that bug 7376 introduces currently. |
| 3017 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2958 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 3018 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
2959 |
( $allowed, $message ) = |
| 3019 |
is( |
2960 |
C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $homebranch->{branchcode} ); |
| 3020 |
0, $allowed, |
2961 |
is( 1, $allowed, 'Allow return where there is no transfer limit between returnbranch and homebranch' ); |
| 3021 |
'Prevent return where item can\'t be transferred to both homebranch and holding from returnbranch' |
2962 |
is( undef, $message, 'without limits provides no message' ); |
| 3022 |
); |
|
|
| 3023 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 3024 |
|
2963 |
|
| 3025 |
$limit_2->delete()->store()->discard_changes; |
2964 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
|
|
2965 |
( $allowed, $message ) = |
| 2966 |
C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $holdingbranch->{branchcode} ); |
| 2967 |
is( 1, $allowed, 'Allow return where there is no transfer limit between returnbranch and holdingbranch' ); |
| 2968 |
is( undef, $message, 'without limits provides no message' ); |
| 3026 |
|
2969 |
|
| 3027 |
# Set limit ( Return -> Holding denied) |
2970 |
# Set limit ( Return -> Home denied) |
|
|
2971 |
diag("Transfer limit: Return -> Home"); |
| 3028 |
$limit->set( |
2972 |
$limit->set( |
| 3029 |
{ |
2973 |
{ |
| 3030 |
toBranch => $holdingbranch->{branchcode}, |
2974 |
toBranch => $homebranch->{branchcode}, |
| 3031 |
fromBranch => $returnbranch->{branchcode} |
2975 |
fromBranch => $returnbranch->{branchcode} |
| 3032 |
} |
2976 |
} |
| 3033 |
)->store()->discard_changes; |
2977 |
)->store()->discard_changes; |
| 3034 |
|
2978 |
|
| 3035 |
diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)"); |
2979 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 3036 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
2980 |
( $allowed, $message ) = |
| 3037 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
2981 |
C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $homebranch->{branchcode} ); |
| 3038 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
2982 |
is( 0, $allowed, 'Prevent return where returnbranch cannot transfer to homebranch' ); |
| 3039 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
|
|
| 3040 |
|
| 3041 |
diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)"); |
| 3042 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 3043 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3044 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 3045 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 3046 |
|
| 3047 |
diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)"); |
| 3048 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 3049 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3050 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 3051 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
2983 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 3052 |
|
2984 |
|
| 3053 |
diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)"); |
|
|
| 3054 |
|
| 3055 |
# NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch' |
| 3056 |
# to 'holdingbranch' (But we can transfer back to 'homebranch'). |
| 3057 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
2985 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 3058 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
2986 |
( $allowed, $message ) = |
| 3059 |
is( |
2987 |
C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $holdingbranch->{branchcode} ); |
| 3060 |
1, $allowed, |
2988 |
is( 1, $allowed, 'Allow return where there is no transfer limit between returnbranch and holdingbranch' ); |
| 3061 |
'Allow return where returnbranch can be transferred to homebranch (holdingbranch forbidden) from returnbranch' |
2989 |
is( undef, $message, 'without limits provides no message' ); |
| 3062 |
); |
2990 |
|
|
|
2991 |
# Set limit ( Return -> Holding denied) |
| 2992 |
diag("Transfer limit: Return -> Holding"); |
| 3063 |
|
2993 |
|
| 3064 |
# Set limit ( Holding -> Home denied) |
2994 |
# Set limit ( Holding -> Home denied) |
| 3065 |
$limit->set( |
2995 |
$limit->set( |
|
Lines 3069-3099
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
Link Here
|
| 3069 |
} |
2999 |
} |
| 3070 |
)->store()->discard_changes; |
3000 |
)->store()->discard_changes; |
| 3071 |
|
3001 |
|
| 3072 |
diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)"); |
3002 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 3073 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
3003 |
( $allowed, $message ) = |
| 3074 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
3004 |
C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $homebranch->{branchcode} ); |
| 3075 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch' ); |
3005 |
is( 1, $allowed, 'Allow return where there is no transfer limit between returnbranch and homebranch' ); |
| 3076 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
3006 |
is( undef, $message, 'without limits provides no message' ); |
| 3077 |
|
|
|
| 3078 |
diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)"); |
| 3079 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 3080 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3081 |
is( 0, $allowed, 'Prevent return where returnbranch != holdingbranch' ); |
| 3082 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 3083 |
|
| 3084 |
diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)"); |
| 3085 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' ); |
| 3086 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
| 3087 |
is( 0, $allowed, 'Prevent return where returnbranch != homebranch or holdingbranch' ); |
| 3088 |
is( $homebranch->{branchcode}, $message, 'Redirect to homebranch' ); |
| 3089 |
|
| 3090 |
diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)"); |
| 3091 |
|
3007 |
|
| 3092 |
# NOTE: A return here can subsequently be transferred to back to homebranch |
|
|
| 3093 |
# or holdingbranch. |
| 3094 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
3008 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 3095 |
( $allowed, $message ) = C4::Circulation::CanBookBeReturned( $item, $returnbranch ); |
3009 |
( $allowed, $message ) = |
| 3096 |
is( 1, $allowed, 'Allow return where returnbranch can be transferred to from anywhere' ); |
3010 |
C4::Circulation::CanBookBeReturned( $item, $returnbranch->{branchcode}, $holdingbranch->{branchcode} ); |
|
|
3011 |
is( 0, $allowed, 'Prevent return where returnbranch cannot transfer to holdingbranch' ); |
| 3012 |
is( $holdingbranch->{branchcode}, $message, 'Redirect to holdingbranch' ); |
| 3097 |
}; |
3013 |
}; |
| 3098 |
|
3014 |
|
| 3099 |
subtest 'Statistic patrons "X"' => sub { |
3015 |
subtest 'Statistic patrons "X"' => sub { |
| 3100 |
- |
|
|