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

(-)a/t/db_dependent/Circulation.t (-9 / +92 lines)
Lines 2349-2355 subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { Link Here
2349
2349
2350
2350
2351
subtest 'AddReturn | is_overdue' => sub {
2351
subtest 'AddReturn | is_overdue' => sub {
2352
    plan tests => 6;
2352
    plan tests => 7;
2353
2353
2354
    t::lib::Mocks::mock_preference('MarkLostItemsAsReturned', 'batchmod|moredetail|cronjob|additem|pendingreserves|onpayment');
2354
    t::lib::Mocks::mock_preference('MarkLostItemsAsReturned', 'batchmod|moredetail|cronjob|additem|pendingreserves|onpayment');
2355
    t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1);
2355
    t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1);
Lines 2385-2390 subtest 'AddReturn | is_overdue' => sub { Link Here
2385
2385
2386
    my $now   = dt_from_string;
2386
    my $now   = dt_from_string;
2387
    my $one_day_ago   = $now->clone->subtract( days => 1 );
2387
    my $one_day_ago   = $now->clone->subtract( days => 1 );
2388
    my $two_days_ago  = $now->clone->subtract( days => 2 );
2388
    my $five_days_ago = $now->clone->subtract( days => 5 );
2389
    my $five_days_ago = $now->clone->subtract( days => 5 );
2389
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2390
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2390
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
2391
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
Lines 2449-2457 subtest 'AddReturn | is_overdue' => sub { Link Here
2449
        Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2450
        Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2450
    };
2451
    };
2451
2452
2452
    subtest 'bug 25417 | backdated return + exemptfine' => sub {
2453
    subtest 'bug 8338 | backdated return resulting in zero amount fine' => sub {
2453
2454
2454
        plan tests => 6;
2455
        plan tests => 17;
2455
2456
2456
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2457
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2457
2458
Lines 2473-2492 subtest 'AddReturn | is_overdue' => sub { Link Here
2473
        is( int( $patron->account->balance() ),
2474
        is( int( $patron->account->balance() ),
2474
            1, "Overdue fine of 1 day overdue" );
2475
            1, "Overdue fine of 1 day overdue" );
2475
2476
2476
        # Backdated return (dropbox mode example - charge should exist but be zero)
2477
        # Backdated return (dropbox mode example - charge should be removed)
2477
        AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago );
2478
        AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago );
2478
        is( int( $patron->account->balance() ),
2479
        is( int( $patron->account->balance() ),
2479
            0, "Overdue fine should be annulled" );
2480
            0, "Overdue fine should be annulled" );
2480
        my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2481
        my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2481
        is( $lines->count, 1, "Overdue fine accountlines still exists");
2482
        is( $lines->count, 0, "Overdue fine accountline has been removed");
2483
2484
        $issue = AddIssue( $patron->unblessed, $item->{barcode}, $two_days_ago );    # date due was 2d ago
2485
2486
        # Fake fines cronjob on this checkout
2487
        ($fine) =
2488
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2489
            $two_days_ago, $now );
2490
        UpdateFine(
2491
            {
2492
                issue_id       => $issue->issue_id,
2493
                itemnumber     => $item->{itemnumber},
2494
                borrowernumber => $patron->borrowernumber,
2495
                amount         => $fine,
2496
                due            => output_pref($one_day_ago)
2497
            }
2498
        );
2499
        is( int( $patron->account->balance() ),
2500
            2, "Overdue fine of 2 days overdue" );
2501
2502
        # Payment made against fine
2503
        $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2504
        my $debit = $lines->next;
2505
        my $credit = $patron->account->add_credit(
2506
            {
2507
                amount    => 2,
2508
                type      => 'PAYMENT',
2509
                interface => 'test',
2510
            }
2511
        );
2512
        $credit->apply(
2513
            { debits => [ $debit ], offset_type => 'Payment' } );
2514
2515
        is( int( $patron->account->balance() ),
2516
            0, "Overdue fine should be paid off" );
2517
        $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2518
        is ( $lines->count, 2, "Overdue (debit) and Payment (credit) present");
2482
        my $line = $lines->next;
2519
        my $line = $lines->next;
2483
        is($line->amount+0,0, "Overdue fine amount has been reduced to 0");
2520
        is( $line->amount+0, 2, "Overdue fine amount remains as 2 days");
2484
        is($line->amountoutstanding+0,0, "Overdue fine amount outstanding has been reduced to 0");
2521
        is( $line->amountoutstanding+0, 0, "Overdue fine amountoutstanding reduced to 0");
2485
        is($line->status,'RETURNED', "Overdue fine was fixed");
2522
2523
        # Backdated return (dropbox mode example - charge should be removed)
2524
        AddReturn( $item->{barcode}, $library->{branchcode}, undef, $one_day_ago );
2525
        is( int( $patron->account->balance() ),
2526
            -1, "Refund credit has been applied" );
2527
        $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber }, { order_by => { '-asc' => 'accountlines_id' }});
2528
        is( $lines->count, 3, "Overdue (debit), Payment (credit) and Refund (credit) are all present");
2529
2530
        $line = $lines->next;
2531
        is($line->amount+0,1, "Overdue fine amount has been reduced to 1");
2532
        is($line->amountoutstanding+0,0, "Overdue fine amount outstanding remains at 0");
2533
        is($line->status,'RETURNED', "Overdue fine is fixed");
2534
        $line = $lines->next;
2535
        is($line->amount+0,-2, "Original payment amount remains as 2");
2536
        is($line->amountoutstanding+0,0, "Original payment remains applied");
2537
        $line = $lines->next;
2538
        is($line->amount+0,-1, "Refund amount correctly set to 1");
2539
        is($line->amountoutstanding+0,-1, "Refund amount outstanding unspent");
2486
2540
2487
        # Cleanup
2541
        # Cleanup
2488
        Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2542
        Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2489
    };
2543
    };
2544
2545
    subtest 'bug 25417 | backdated return + exemptfine' => sub {
2546
2547
        plan tests => 2;
2548
2549
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2550
2551
        my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $one_day_ago );    # date due was 1d ago
2552
2553
        # Fake fines cronjob on this checkout
2554
        my ($fine) =
2555
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2556
            $one_day_ago, $now );
2557
        UpdateFine(
2558
            {
2559
                issue_id       => $issue->issue_id,
2560
                itemnumber     => $item->{itemnumber},
2561
                borrowernumber => $patron->borrowernumber,
2562
                amount         => $fine,
2563
                due            => output_pref($one_day_ago)
2564
            }
2565
        );
2566
        is( int( $patron->account->balance() ),
2567
            1, "Overdue fine of 1 day overdue" );
2568
2569
        # Backdated return (dropbox mode example - charge should no longer exist)
2570
        AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago );
2571
        is( int( $patron->account->balance() ),
2572
            0, "Overdue fine should be annulled" );
2573
    };
2490
};
2574
};
2491
2575
2492
subtest '_FixAccountForLostAndFound' => sub {
2576
subtest '_FixAccountForLostAndFound' => sub {
2493
- 

Return to bug 8338