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

(-)a/t/db_dependent/Circulation.t (-9 / +92 lines)
Lines 2337-2343 subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { Link Here
2337
2337
2338
2338
2339
subtest 'AddReturn | is_overdue' => sub {
2339
subtest 'AddReturn | is_overdue' => sub {
2340
    plan tests => 6;
2340
    plan tests => 7;
2341
2341
2342
    t::lib::Mocks::mock_preference('MarkLostItemsAsReturned', 'batchmod|moredetail|cronjob|additem|pendingreserves|onpayment');
2342
    t::lib::Mocks::mock_preference('MarkLostItemsAsReturned', 'batchmod|moredetail|cronjob|additem|pendingreserves|onpayment');
2343
    t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1);
2343
    t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1);
Lines 2373-2378 subtest 'AddReturn | is_overdue' => sub { Link Here
2373
2373
2374
    my $now   = dt_from_string;
2374
    my $now   = dt_from_string;
2375
    my $one_day_ago   = $now->clone->subtract( days => 1 );
2375
    my $one_day_ago   = $now->clone->subtract( days => 1 );
2376
    my $two_days_ago  = $now->clone->subtract( days => 2 );
2376
    my $five_days_ago = $now->clone->subtract( days => 5 );
2377
    my $five_days_ago = $now->clone->subtract( days => 5 );
2377
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2378
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2378
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
2379
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
Lines 2437-2445 subtest 'AddReturn | is_overdue' => sub { Link Here
2437
        Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2438
        Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2438
    };
2439
    };
2439
2440
2440
    subtest 'bug 25417 | backdated return + exemptfine' => sub {
2441
    subtest 'bug 8338 | backdated return resulting in zero amount fine' => sub {
2441
2442
2442
        plan tests => 6;
2443
        plan tests => 17;
2443
2444
2444
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2445
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2445
2446
Lines 2461-2480 subtest 'AddReturn | is_overdue' => sub { Link Here
2461
        is( int( $patron->account->balance() ),
2462
        is( int( $patron->account->balance() ),
2462
            1, "Overdue fine of 1 day overdue" );
2463
            1, "Overdue fine of 1 day overdue" );
2463
2464
2464
        # Backdated return (dropbox mode example - charge should exist but be zero)
2465
        # Backdated return (dropbox mode example - charge should be removed)
2465
        AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago );
2466
        AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago );
2466
        is( int( $patron->account->balance() ),
2467
        is( int( $patron->account->balance() ),
2467
            0, "Overdue fine should be annulled" );
2468
            0, "Overdue fine should be annulled" );
2468
        my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2469
        my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2469
        is( $lines->count, 1, "Overdue fine accountlines still exists");
2470
        is( $lines->count, 0, "Overdue fine accountline has been removed");
2471
2472
        $issue = AddIssue( $patron->unblessed, $item->{barcode}, $two_days_ago );    # date due was 2d ago
2473
2474
        # Fake fines cronjob on this checkout
2475
        ($fine) =
2476
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2477
            $two_days_ago, $now );
2478
        UpdateFine(
2479
            {
2480
                issue_id       => $issue->issue_id,
2481
                itemnumber     => $item->{itemnumber},
2482
                borrowernumber => $patron->borrowernumber,
2483
                amount         => $fine,
2484
                due            => output_pref($one_day_ago)
2485
            }
2486
        );
2487
        is( int( $patron->account->balance() ),
2488
            2, "Overdue fine of 2 days overdue" );
2489
2490
        # Payment made against fine
2491
        $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2492
        my $debit = $lines->next;
2493
        my $credit = $patron->account->add_credit(
2494
            {
2495
                amount    => 2,
2496
                type      => 'PAYMENT',
2497
                interface => 'test',
2498
            }
2499
        );
2500
        $credit->apply(
2501
            { debits => [ $debit ], offset_type => 'Payment' } );
2502
2503
        is( int( $patron->account->balance() ),
2504
            0, "Overdue fine should be paid off" );
2505
        $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber });
2506
        is ( $lines->count, 2, "Overdue (debit) and Payment (credit) present");
2470
        my $line = $lines->next;
2507
        my $line = $lines->next;
2471
        is($line->amount+0,0, "Overdue fine amount has been reduced to 0");
2508
        is( $line->amount+0, 2, "Overdue fine amount remains as 2 days");
2472
        is($line->amountoutstanding+0,0, "Overdue fine amount outstanding has been reduced to 0");
2509
        is( $line->amountoutstanding+0, 0, "Overdue fine amountoutstanding reduced to 0");
2473
        is($line->status,'RETURNED', "Overdue fine was fixed");
2510
2511
        # Backdated return (dropbox mode example - charge should be removed)
2512
        AddReturn( $item->{barcode}, $library->{branchcode}, undef, $one_day_ago );
2513
        is( int( $patron->account->balance() ),
2514
            -1, "Refund credit has been applied" );
2515
        $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber }, { order_by => { '-asc' => 'accountlines_id' }});
2516
        is( $lines->count, 3, "Overdue (debit), Payment (credit) and Refund (credit) are all present");
2517
       
2518
        $line = $lines->next;
2519
        is($line->amount+0,1, "Overdue fine amount has been reduced to 1");
2520
        is($line->amountoutstanding+0,0, "Overdue fine amount outstanding remains at 0");
2521
        is($line->status,'RETURNED', "Overdue fine is fixed");
2522
        $line = $lines->next;
2523
        is($line->amount+0,-2, "Original payment amount remains as 2");
2524
        is($line->amountoutstanding+0,0, "Original payment remains applied");
2525
        $line = $lines->next;
2526
        is($line->amount+0,-1, "Refund amount correctly set to 1");
2527
        is($line->amountoutstanding+0,-1, "Refund amount outstanding unspent");
2474
2528
2475
        # Cleanup
2529
        # Cleanup
2476
        Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2530
        Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2477
    };
2531
    };
2532
2533
    subtest 'bug 25417 | backdated return + exemptfine' => sub {
2534
2535
        plan tests => 2;
2536
2537
        t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1);
2538
2539
        my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $one_day_ago );    # date due was 1d ago
2540
2541
        # Fake fines cronjob on this checkout
2542
        my ($fine) =
2543
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2544
            $one_day_ago, $now );
2545
        UpdateFine(
2546
            {
2547
                issue_id       => $issue->issue_id,
2548
                itemnumber     => $item->{itemnumber},
2549
                borrowernumber => $patron->borrowernumber,
2550
                amount         => $fine,
2551
                due            => output_pref($one_day_ago)
2552
            }
2553
        );
2554
        is( int( $patron->account->balance() ),
2555
            1, "Overdue fine of 1 day overdue" );
2556
2557
        # Backdated return (dropbox mode example - charge should no longer exist)
2558
        AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago );
2559
        is( int( $patron->account->balance() ),
2560
            0, "Overdue fine should be annulled" );
2561
    };
2478
};
2562
};
2479
2563
2480
subtest '_FixAccountForLostAndFound' => sub {
2564
subtest '_FixAccountForLostAndFound' => sub {
2481
- 

Return to bug 8338