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

(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-2 / +14 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 6;
20
use Test::More tests => 7;
21
21
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 35-41 my $builder = t::lib::TestBuilder->new(); Link Here
35
35
36
my $item = $builder->build_sample_item;
36
my $item = $builder->build_sample_item;
37
37
38
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
38
my $patron_category = $builder->build(
39
    {
40
        source => 'Category',
41
        value  => {
42
            categorycode   => 'NOT_X', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0,
43
            noissuescharge => 0,  noissueschargeguarantorswithguarantees => 0
44
        }
45
    }
46
);
39
my $patron = $builder->build_object(
47
my $patron = $builder->build_object(
40
    {
48
    {
41
        class => 'Koha::Patrons',
49
        class => 'Koha::Patrons',
Lines 76-81 $account->add_debit({ amount => 10.00, type => 'LOST', interface => 'test' }); Link Here
76
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode );
84
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode );
77
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
85
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
78
86
87
$patron->category->noissueschargeguarantees(11);
88
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode );
89
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item as the patron category limit is now higher than 10" );
90
79
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
91
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
80
is( $accountline->amountoutstanding+0, 10, "Found 10.00 amount outstanding" );
92
is( $accountline->amountoutstanding+0, 10, "Found 10.00 amount outstanding" );
81
is( $accountline->debit_type_code, "LOST", "Debit type is LOST" );
93
is( $accountline->debit_type_code, "LOST", "Debit type is LOST" );
(-)a/t/db_dependent/Koha/Patron.t (-1 / +241 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 33;
22
use Test::More tests => 35;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
use Time::Fake;
25
use Time::Fake;
Lines 2246-2251 subtest 'guarantor requirements tests' => sub { Link Here
2246
    throws_ok { $child2->store(); }
2246
    throws_ok { $child2->store(); }
2247
    'Koha::Exceptions::Patron::Relationship::NoGuarantor',
2247
    'Koha::Exceptions::Patron::Relationship::NoGuarantor',
2248
        'Exception thrown when guarantor is deleted.';
2248
        'Exception thrown when guarantor is deleted.';
2249
2250
    $schema->storage->txn_rollback;
2251
};
2252
2253
subtest 'can_borrow() tests' => sub {
2254
    plan tests => 11;
2255
    $schema->storage->txn_begin;
2256
2257
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
2258
2259
    my $patron_category = $builder->build(
2260
        {
2261
            source => 'Category',
2262
            value  => {
2263
                categorycode   => 'NOT_X', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0,
2264
                noissuescharge => 10,      noissueschargeguarantorswithguarantees => 0
2265
            }
2266
        }
2267
    );
2268
2269
    my $patron = $builder->build_object(
2270
        {
2271
            class => 'Koha::Patrons',
2272
            value => {
2273
                categorycode => $patron_category->{categorycode},
2274
            }
2275
        }
2276
    );
2277
    my $patron_borrowing_status;
2278
2279
    $patron->debarred(1);
2280
    $patron_borrowing_status = $patron->can_borrow( { patron => $patron } );
2281
    is( $patron_borrowing_status->{can_borrow}, 0, 'Debarred patron blocked from borrowing' );
2282
    is( $patron_borrowing_status->{debarred},   1, 'Blocker correctly identified and returned' );
2283
    $patron->debarred(0);
2284
2285
    $patron->dateexpiry( dt_from_string->subtract( days => 1 ) );
2286
    $patron_borrowing_status = $patron->can_borrow( { patron => $patron } );
2287
    is( $patron_borrowing_status->{can_borrow}, 0, 'Expired patron blocked from borrowing' );
2288
    is( $patron_borrowing_status->{expired},    1, 'Blocker correctly identified and returned' );
2289
    $patron->dateexpiry(undef);
2290
2291
    my $child   = $builder->build_object( { class => 'Koha::Patrons' } );
2292
    my $sibling = $builder->build_object( { class => 'Koha::Patrons' } );
2293
    $child->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } );
2294
    $sibling->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } );
2295
2296
    t::lib::Mocks::mock_preference( 'noissuescharge', 50 );
2297
2298
    my $fee1 = $builder->build_object(
2299
        {
2300
            class => 'Koha::Account::Lines',
2301
            value => {
2302
                borrowernumber    => $patron->borrowernumber,
2303
                amountoutstanding => 11,
2304
                debit_type_code   => 'OVERDUE',
2305
            }
2306
        }
2307
    )->store;
2308
2309
    my $fee2 = $builder->build_object(
2310
        {
2311
            class => 'Koha::Account::Lines',
2312
            value => {
2313
                borrowernumber    => $child->borrowernumber,
2314
                amountoutstanding => 0.11,
2315
                debit_type_code   => 'OVERDUE',
2316
            }
2317
        }
2318
    )->store;
2319
2320
    my $fee3 = $builder->build_object(
2321
        {
2322
            class => 'Koha::Account::Lines',
2323
            value => {
2324
                borrowernumber    => $sibling->borrowernumber,
2325
                amountoutstanding => 11.11,
2326
                debit_type_code   => 'OVERDUE',
2327
            }
2328
        }
2329
    )->store;
2330
2331
    $patron_borrowing_status = $patron->can_borrow( { patron => $patron } );
2332
2333
    is( $patron_borrowing_status->{noissuescharge}->{charge},    11, "Only patron's fines are reported in total" );
2334
    is( $patron_borrowing_status->{noissuescharge}->{limit},     10, "Limit correctly identified at category level" );
2335
    is( $patron_borrowing_status->{noissuescharge}->{overlimit}, 1,  "Patron is over the charge limit" );
2336
    is( $patron_borrowing_status->{can_borrow}, 0, "Patron is over the charge limit and is blocked from borrowing" );
2337
    $patron->category->noissuescharge(undef);
2338
2339
    $patron_borrowing_status = $patron->can_borrow( { patron => $patron } );
2340
    is( $patron_borrowing_status->{noissuescharge}->{limit}, 50, "Limit correctly identified at global syspref level" );
2341
    is( $patron_borrowing_status->{noissuescharge}->{overlimit}, 0, "Patron is within the charge limit" );
2342
    is( $patron_borrowing_status->{can_borrow}, 1, "Patron is within the charge limit and can borrow" );
2343
2344
    $schema->storage->txn_rollback;
2345
};
2346
2347
subtest 'is_patron_inside_charge_limits() tests' => sub {
2348
    plan tests => 21;
2349
    $schema->storage->txn_begin;
2350
2351
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'parent' );
2352
2353
    my $patron_category = $builder->build(
2354
        {
2355
            source => 'Category',
2356
            value  => {
2357
                categorycode   => 'NOT_X', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0,
2358
                noissuescharge => 10,      noissueschargeguarantorswithguarantees => 0
2359
            }
2360
        }
2361
    );
2362
2363
    my $patron = $builder->build_object(
2364
        {
2365
            class => 'Koha::Patrons',
2366
            value => {
2367
                categorycode => $patron_category->{categorycode},
2368
            }
2369
        }
2370
    );
2371
2372
    my $child   = $builder->build_object( { class => 'Koha::Patrons' } );
2373
    my $sibling = $builder->build_object( { class => 'Koha::Patrons' } );
2374
    $child->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } );
2375
    $sibling->add_guarantor( { guarantor_id => $patron->borrowernumber, relationship => 'parent' } );
2376
2377
    t::lib::Mocks::mock_preference( 'noissuescharge',                         50 );
2378
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees',               11.01 );
2379
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantorsWithGuarantees', undef );
2380
2381
    my $fee1 = $builder->build_object(
2382
        {
2383
            class => 'Koha::Account::Lines',
2384
            value => {
2385
                borrowernumber    => $patron->borrowernumber,
2386
                amountoutstanding => 11,
2387
                debit_type_code   => 'OVERDUE',
2388
            }
2389
        }
2390
    )->store;
2391
2392
    my $fee2 = $builder->build_object(
2393
        {
2394
            class => 'Koha::Account::Lines',
2395
            value => {
2396
                borrowernumber    => $child->borrowernumber,
2397
                amountoutstanding => 0.11,
2398
                debit_type_code   => 'OVERDUE',
2399
            }
2400
        }
2401
    )->store;
2402
2403
    my $fee3 = $builder->build_object(
2404
        {
2405
            class => 'Koha::Account::Lines',
2406
            value => {
2407
                borrowernumber    => $sibling->borrowernumber,
2408
                amountoutstanding => 11.11,
2409
                debit_type_code   => 'OVERDUE',
2410
            }
2411
        }
2412
    )->store;
2413
2414
    my $patron_borrowing_status;
2415
    $patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } );
2416
2417
    is( $patron_borrowing_status->{noissuescharge}->{charge},    11, "Only patron's fines are reported in total" );
2418
    is( $patron_borrowing_status->{noissuescharge}->{limit},     10, "Limit correctly identified at category level" );
2419
    is( $patron_borrowing_status->{noissuescharge}->{overlimit}, 1,  "Patron is over the charge limit" );
2420
2421
    $patron->category->noissuescharge(undef);
2422
    $patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } );
2423
    is( $patron_borrowing_status->{noissuescharge}->{limit}, 50, "Limit correctly identified at global syspref level" );
2424
    is( $patron_borrowing_status->{noissuescharge}->{charge},    11, "Charges correctly identified" );
2425
    is( $patron_borrowing_status->{noissuescharge}->{overlimit}, 0,  "Patron is within the charge limit" );
2426
2427
    is(
2428
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{limit}, 11.01,
2429
        "Limit correctly identified at global syspref level"
2430
    );
2431
    is( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge},    11.22, "Charges correctly identified" );
2432
    is( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit}, 1,     "Patron is over the charge limit" );
2433
2434
    $patron->category->noissueschargeguarantees(12);
2435
    $patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } );
2436
    is(
2437
        $patron_borrowing_status->{NoIssuesChargeGuarantees}->{limit}, 12,
2438
        "Limit correctly identified at patron category level"
2439
    );
2440
    is( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{charge},    11.22, "Charges correctly identified" );
2441
    is( $patron_borrowing_status->{NoIssuesChargeGuarantees}->{overlimit}, 0,     "Patron is inside the charge limit" );
2442
2443
    is(
2444
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit}, 0,
2445
        "Limit correctly identified as not set at either patron category or global syspref level"
2446
    );
2447
    is(
2448
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}, 22.22,
2449
        "Charges correctly identified"
2450
    );
2451
    is(
2452
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}, 0,
2453
        "Patron is inside the charge limit as no limit has been set"
2454
    );
2455
2456
    $patron->category->noissueschargeguarantorswithguarantees(23);
2457
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantorsWithGuarantees', 20 );
2458
    $patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } );
2459
    is(
2460
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit}, 23,
2461
        "Limit correctly identified at patron category level"
2462
    );
2463
    is(
2464
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}, 22.22,
2465
        "Charges correctly identified"
2466
    );
2467
    is(
2468
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}, 0,
2469
        "Patron is inside the charge limit"
2470
    );
2471
2472
    $patron->category->noissueschargeguarantorswithguarantees(undef);
2473
    t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantorsWithGuarantees', 20 );
2474
    $patron_borrowing_status = $patron->is_patron_inside_charge_limits( { patron => $patron } );
2475
    is(
2476
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{limit}, 20,
2477
        "Limit correctly defaults to global syspref"
2478
    );
2479
    is(
2480
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{charge}, 22.22,
2481
        "Charges correctly identified"
2482
    );
2483
    is(
2484
        $patron_borrowing_status->{NoIssuesChargeGuarantorsWithGuarantees}->{overlimit}, 1,
2485
        "Patron is inside the charge limit"
2486
    );
2487
2488
    $schema->storage->txn_rollback;
2249
};
2489
};
2250
2490
2251
subtest 'Scrub the note fields' => sub {
2491
subtest 'Scrub the note fields' => sub {
(-)a/t/db_dependent/SIP/Patron.t (-3 / +44 lines)
Lines 316-322 subtest "NoIssuesChargeGuarantees tests" => sub { Link Here
316
316
317
    $schema->storage->txn_begin;
317
    $schema->storage->txn_begin;
318
318
319
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
319
    my $patron_category = $builder->build(
320
        {
321
            source => 'Category',
322
            value  => {
323
                categorycode   => 'NOT_X', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0,
324
                noissuescharge => 0,       noissueschargeguarantorswithguarantees => 0
325
            }
326
        }
327
    );
328
329
    my $patron = $builder->build_object(
330
        {
331
            class => 'Koha::Patrons',
332
            value => {
333
                categorycode => $patron_category->{categorycode},
334
            }
335
        }
336
    );
320
    my $child  = $builder->build_object({ class => 'Koha::Patrons' });
337
    my $child  = $builder->build_object({ class => 'Koha::Patrons' });
321
    my $sibling  = $builder->build_object({ class => 'Koha::Patrons' });
338
    my $sibling  = $builder->build_object({ class => 'Koha::Patrons' });
322
    $child->add_guarantor({ guarantor_id => $patron->borrowernumber, relationship => 'parent' });
339
    $child->add_guarantor({ guarantor_id => $patron->borrowernumber, relationship => 'parent' });
Lines 382-389 subtest "NoIssuesChargeGuarantorsWithGuarantees tests" => sub { Link Here
382
399
383
    $schema->storage->txn_begin;
400
    $schema->storage->txn_begin;
384
401
385
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
402
    my $patron_category = $builder->build(
386
    my $child  = $builder->build_object({ class => 'Koha::Patrons' });
403
        {
404
            source => 'Category',
405
            value  => {
406
                categorycode   => 'NOT_X', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0,
407
                noissuescharge => 0,       noissueschargeguarantorswithguarantees => 0
408
            }
409
        }
410
    );
411
412
    my $patron = $builder->build_object(
413
        {
414
            class => 'Koha::Patrons',
415
            value => {
416
                categorycode => $patron_category->{categorycode},
417
            }
418
        }
419
    );
420
    my $child = $builder->build_object(
421
        {
422
            class => 'Koha::Patrons',
423
            value => {
424
                categorycode => $patron_category->{categorycode},
425
            }
426
        }
427
    );
387
    $child->add_guarantor({ guarantor_id => $patron->borrowernumber, relationship => 'parent' });
428
    $child->add_guarantor({ guarantor_id => $patron->borrowernumber, relationship => 'parent' });
388
429
389
    t::lib::Mocks::mock_preference('noissuescharge', 50);
430
    t::lib::Mocks::mock_preference('noissuescharge', 50);
(-)a/t/db_dependent/SIP/Transaction.t (-1 / +23 lines)
Lines 645-655 subtest do_checkout_with_sysprefs_override => sub { Link Here
645
        }
645
        }
646
    );
646
    );
647
647
648
    my $patron_category = $builder->build(
649
        {
650
            source => 'Category',
651
            value  => {
652
                categorycode   => 'NOT_X', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0,
653
                noissuescharge => 0,       noissueschargeguarantorswithguarantees => 0
654
            }
655
        }
656
    );
657
648
    my $patron_under_noissuescharge = $builder->build_object(
658
    my $patron_under_noissuescharge = $builder->build_object(
649
        {
659
        {
650
            class => 'Koha::Patrons',
660
            class => 'Koha::Patrons',
651
            value => {
661
            value => {
652
                branchcode => $library->branchcode,
662
                branchcode => $library->branchcode,
663
                categorycode => $patron_category->{categorycode},
653
            }
664
            }
654
        }
665
        }
655
    );
666
    );
Lines 671-676 subtest do_checkout_with_sysprefs_override => sub { Link Here
671
            class => 'Koha::Patrons',
682
            class => 'Koha::Patrons',
672
            value => {
683
            value => {
673
                branchcode => $library->branchcode,
684
                branchcode => $library->branchcode,
685
                categorycode => $patron_category->{categorycode},
674
            }
686
            }
675
        }
687
        }
676
    );
688
    );
Lines 779-784 subtest do_checkout_with_patron_blocked => sub { Link Here
779
            library => $library->branchcode,
791
            library => $library->branchcode,
780
        }
792
        }
781
    );
793
    );
794
    
795
    my $patron_category = $builder->build(
796
        {
797
            source => 'Category',
798
            value  => {
799
                categorycode   => 'NOT_X2', category_type => 'P', enrolmentfee => 0, noissueschargeguarantees => 0,
800
                noissuescharge => 0,       noissueschargeguarantorswithguarantees => 0
801
            }
802
        }
803
    );
782
804
783
    my $expired_patron = $builder->build_object(
805
    my $expired_patron = $builder->build_object(
784
        {
806
        {
Lines 797-802 subtest do_checkout_with_patron_blocked => sub { Link Here
797
            class => 'Koha::Patrons',
819
            class => 'Koha::Patrons',
798
            value => {
820
            value => {
799
                branchcode => $library->branchcode,
821
                branchcode => $library->branchcode,
822
                categorycode => $patron_category->{categorycode},
800
            }
823
            }
801
        }
824
        }
802
    );
825
    );
803
- 

Return to bug 28924