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

(-)a/t/db_dependent/Circulation.t (-122 / +45 lines)
Lines 2211-2218 subtest 'AddIssue & illrequests.due_date' => sub { Link Here
2211
    is( $issue->date_due, $expected_date_due, 'Custom illrequest date due has been set for this issue');
2211
    is( $issue->date_due, $expected_date_due, 'Custom illrequest date due has been set for this issue');
2212
};
2212
};
2213
2213
2214
subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub {
2214
subtest 'CanBookBeReturned + UseBranchTransfertLimits + CirculationRules' => sub {
2215
    plan tests => 33;
2215
    plan tests => 22;
2216
2216
2217
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
2217
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
2218
2218
Lines 2232-2364 subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { Link Here
2232
    set_userenv($holdingbranch);
2232
    set_userenv($holdingbranch);
2233
    my $issue = AddIssue( $patron, $item->barcode );
2233
    my $issue = AddIssue( $patron, $item->barcode );
2234
2234
2235
    # 'Anywhere' + BranchTransferLimits
2235
    # Attempt returns at returnbranch
2236
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2237
2238
    # Attempt return at returnbranch (No limits defined)
2239
    my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2240
    is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed');
2241
    is ( undef , $message , 'without limits provides no message');
2242
2243
    # Set limit (Holding -> Return denied)
2244
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
2245
    my $limit = Koha::Item::Transfer::Limit->new({
2246
        toBranch   => $returnbranch->{branchcode},
2247
        fromBranch => $holdingbranch->{branchcode},
2248
        itemtype   => $item->effective_itemtype,
2249
    })->store();
2250
2251
    diag("Attempt return at returnbranch ('Homebranch' + Holding -> Return limit)");
2252
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2236
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2253
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2237
    my ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2254
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2238
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2255
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2239
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2256
2240
2257
    diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Return limit)");
2258
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2241
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2259
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2242
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2260
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2243
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2261
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2244
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2262
2245
2263
    diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Return limit)");
2264
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2246
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2265
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2247
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2266
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2248
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2267
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2249
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2268
2250
2269
    diag("Attempt return at returnbranch ('Anywhere' + Holding -> Return limit)");
2270
    # NOTE: This prevents receiving an item from a branch that is listed in
2271
    # the branchtransferlimits as not allowed to send to our returnbranch.
2272
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2251
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2273
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2252
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2274
    is ( 0 , $allowed , 'Prevent return where returnbranch has a branchtransfer limit from holdingbranch');
2253
    is ( 1 , $allowed , 'with AllowReturnToBranch = anywhere and no limits return to returnbranch is allowed');
2275
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2254
    is ( undef , $message , 'without limits provides no message');
2276
2277
    # Set limit ( Return -> Home denied)
2278
    $limit->set(
2279
        {
2280
            toBranch   => $homebranch->{branchcode},
2281
            fromBranch => $returnbranch->{branchcode}
2282
        }
2283
    )->store()->discard_changes;
2284
2285
    diag("Attempt return at returnbranch ('Homebranch' + Return -> Home limit)");
2286
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2287
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2288
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2289
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2290
2291
    diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Home limit)");
2292
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2293
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2294
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2295
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2296
2297
    diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Home limit)");
2298
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2299
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2300
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2301
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2302
2303
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Home limit)");
2304
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2305
    # to 'homebranch' (But we can transfer back to 'holdingbranch').
2306
    # NOTE: This is the ONLY change that bug 7376 introduces currently.
2307
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2308
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2309
    is ( 1 , $allowed , 'Allow return where returnbranch can be transfered to holding (homebranch forbidden) from returnbranch');
2310
2255
2311
    my $limit_2 = Koha::Item::Transfer::Limit->new({
2256
    # Set limit (Holding -> Return denied)
2312
        toBranch   => $holdingbranch->{branchcode},
2257
    diag("Transfer limit: Holding -> Return");
2313
        fromBranch => $returnbranch->{branchcode},
2258
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
2259
    my $limit = Koha::Item::Transfer::Limit->new({
2260
        toBranch   => $returnbranch->{branchcode},
2261
        fromBranch => $holdingbranch->{branchcode},
2314
        itemtype   => $item->effective_itemtype,
2262
        itemtype   => $item->effective_itemtype,
2315
    })->store();
2263
    })->store();
2316
2264
2317
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Home and Return -> Holding limit)");
2318
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2319
    # to 'homebranch' (But we can transfer back to 'holdingbranch').
2320
    # NOTE: This is the ONLY change that bug 7376 introduces currently.
2321
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2265
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2322
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2266
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode});
2323
    is ( 0 , $allowed , 'Prevent return where item can\'t be transferred to both homebranch and holding from returnbranch');
2267
    is ( 1 , $allowed , 'Allow return where transferbranch is not passed');
2324
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2268
    is ( undef , $message , 'without limits provides no message');
2269
2270
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2271
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode});
2272
    is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and homebranch');
2273
    is ( undef , $message , 'without limits provides no message');
2325
2274
2326
    $limit_2->delete()->store()->discard_changes;
2275
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2276
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode});
2277
    is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and holdingbranch');
2278
    is ( undef , $message , 'without limits provides no message');
2327
2279
2328
    # Set limit ( Return -> Holding denied)
2280
    # Set limit ( Return -> Home denied)
2281
    diag("Transfer limit: Return -> Home");
2329
    $limit->set(
2282
    $limit->set(
2330
        {
2283
        {
2331
            toBranch   => $holdingbranch->{branchcode},
2284
            toBranch   => $homebranch->{branchcode},
2332
            fromBranch => $returnbranch->{branchcode}
2285
            fromBranch => $returnbranch->{branchcode}
2333
        }
2286
        }
2334
    )->store()->discard_changes;
2287
    )->store()->discard_changes;
2335
2288
2336
    diag("Attempt return at returnbranch ('Homebranch' + Return -> Holding limit)");
2289
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2337
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2290
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode});
2338
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2291
    is ( 0 , $allowed , 'Prevent return where returnbranch cannot transfer to homebranch');
2339
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2340
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2341
2342
    diag("Attempt return at returnbranch ('Holdingbranch' + Return -> Holding limit)");
2343
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2344
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2345
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2346
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2347
2348
    diag("Attempt return at returnbranch ('Home Or Holding' + Return -> Holding limit)");
2349
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2350
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2351
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2352
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2292
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2353
2293
2354
    diag("Attempt return at returnbranch ('Anywhere' + Return -> Holding limit)");
2355
    # NOTE: Should we prevent return here.. we cannot transfer from 'returnbranch'
2356
    # to 'holdingbranch' (But we can transfer back to 'homebranch').
2357
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2294
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2358
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2295
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode});
2359
    is ( 1 , $allowed , 'Allow return where returnbranch can be transferred to homebranch (holdingbranch forbidden) from returnbranch');
2296
    is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and holdingbranch');
2297
    is ( undef , $message , 'without limits provides no message');
2360
2298
2361
    # Set limit ( Holding -> Home denied)
2299
    # Set limit ( Return -> Holding denied)
2300
    diag("Transfer limit: Return -> Holding");
2362
    $limit->set(
2301
    $limit->set(
2363
        {
2302
        {
2364
            toBranch   => $holdingbranch->{branchcode},
2303
            toBranch   => $holdingbranch->{branchcode},
Lines 2366-2395 subtest 'CanBookBeReturned + UseBranchTransfertLimits' => sub { Link Here
2366
        }
2305
        }
2367
    )->store()->discard_changes;
2306
    )->store()->discard_changes;
2368
2307
2369
    diag("Attempt return at returnbranch ('Homebranch' + Holding -> Home limit)");
2308
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2370
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' );
2309
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $homebranch->{branchcode});
2371
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2310
    is ( 1 , $allowed , 'Allow return where there is no transfer limit between returnbranch and homebranch');
2372
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch');
2311
    is ( undef , $message , 'without limits provides no message');
2373
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2374
2375
    diag("Attempt return at returnbranch ('Holdingbranch' + Holding -> Home limit)");
2376
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' );
2377
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2378
    is ( 0 , $allowed , 'Prevent return where returnbranch != holdingbranch');
2379
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2380
2381
    diag("Attempt return at returnbranch ('Home Or Holding' + Holding -> Home limit)");
2382
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homeorholdingbranch' );
2383
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2384
    is ( 0 , $allowed , 'Prevent return where returnbranch != homebranch or holdingbranch');
2385
    is ( $homebranch->{branchcode} , $message , 'Redirect to homebranch');
2386
2312
2387
    diag("Attempt return at returnbranch ('Anywhere' + Holding -> Home limit)");
2388
    # NOTE: A return here can subsequently be transferred to back to homebranch
2389
    # or holdingbranch.
2390
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2313
    t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' );
2391
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch);
2314
    ($allowed, $message) = C4::Circulation::CanBookBeReturned($item, $returnbranch->{branchcode}, $holdingbranch->{branchcode});
2392
    is ( 1 , $allowed , 'Allow return where returnbranch can be transferred to from anywhere');
2315
    is ( 0 , $allowed , 'Prevent return where returnbranch cannot transfer to holdingbranch');
2316
    is ( $holdingbranch->{branchcode} , $message , 'Redirect to holdingbranch');
2393
};
2317
};
2394
2318
2395
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub {
2319
subtest 'CanBookBeIssued + Koha::Patron->is_debarred|has_overdues' => sub {
2396
- 

Return to bug 7376