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

(-)a/t/db_dependent/Circulation.t (-25 / +37 lines)
Lines 1985-1991 subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { Link Here
1985
1985
1986
1986
1987
subtest 'AddReturn | is_overdue' => sub {
1987
subtest 'AddReturn | is_overdue' => sub {
1988
    plan tests => 8;
1988
    plan tests => 5;
1989
1989
1990
    t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1);
1990
    t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1);
1991
    t::lib::Mocks::mock_preference('finesMode', 'production');
1991
    t::lib::Mocks::mock_preference('finesMode', 'production');
Lines 2044-2092 subtest 'AddReturn | is_overdue' => sub { Link Here
2044
    my $ten_days_ago  = dt_from_string->subtract( days => 10 );
2044
    my $ten_days_ago  = dt_from_string->subtract( days => 10 );
2045
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
2045
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
2046
2046
2047
    # No date specify, today will be used
2047
    # No return date specified, today will be used => 10 days overdue charged
2048
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2048
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2049
    AddReturn( $item->{barcode}, $library->{branchcode} );
2049
    AddReturn( $item->{barcode}, $library->{branchcode} );
2050
    is( int($patron->account->balance()), 10, 'Patron should have a charge of 10 (10 days x 1)' );
2050
    is( int($patron->account->balance()), 10, 'Patron should have a charge of 10 (10 days x 1)' );
2051
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2051
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2052
2052
2053
    # specify return date 5 days before => no overdue
2053
    # specify return date 5 days before => no overdue charged
2054
    AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
2054
    AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
2055
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, $ten_days_ago );
2055
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, $ten_days_ago );
2056
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2056
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2057
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2057
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2058
2058
2059
    # specify return date 5 days later => overdue
2059
    # specify return date 5 days later => 5 days overdue charged
2060
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2060
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2061
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, $five_days_ago );
2061
    AddReturn( $item->{barcode}, $library->{branchcode}, undef, $five_days_ago );
2062
    is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
2062
    is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
2063
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2063
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2064
2064
2065
    # specify dropbox date 5 days before => no overdue
2065
    # specify return date 5 days later, specify exemptfine => no overdue charge
2066
    AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
2066
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2067
    AddReturn( $item->{barcode}, $library->{branchcode}, $ten_days_ago );
2067
    AddReturn( $item->{barcode}, $library->{branchcode}, 1, $five_days_ago );
2068
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2068
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2069
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2069
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2070
2070
2071
    # specify dropbox date 5 days later => overdue, or... not
2071
    subtest 'bug 22877' => sub {
2072
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2073
    AddReturn( $item->{barcode}, $library->{branchcode}, $five_days_ago );
2074
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the OVERDUE fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature
2075
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2076
2072
2077
    # Checkout an item 10 days ago
2073
        plan tests => 3;
2078
    my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2074
2079
    # Fake fines cronjob on this checkout
2075
        my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago );    # date due was 10d ago
2080
    my ( $fine ) = CalcFine( $item , $patron->categorycode, $library->{branchcode}, $ten_days_ago, $now );
2081
    UpdateFine({ issue_id => $issue->issue_id, itemnumber => $item->{itemnumber}, borrowernumber => $patron->borrowernumber, amount => $fine, due => output_pref($ten_days_ago) });
2082
    is( int($patron->account->balance()),10, "Overdue fine of 10 days overdue");
2083
    # Fake longoverdue with charge and not marking returned
2084
    LostItem( $item->{itemnumber}, 'cronjob',0 );
2085
    is( int($patron->account->balance()),17, "Lost fine of 7 plus 10 days overdue");
2086
    # Now we return it today
2087
    AddReturn( $item->{barcode}, $library->{branchcode} );
2088
    is( int($patron->account->balance()),17, "Should have a single 10 days overdue fine and lost charge");
2089
2076
2077
        # Fake fines cronjob on this checkout
2078
        my ($fine) =
2079
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2080
            $ten_days_ago, $now );
2081
        UpdateFine(
2082
            {
2083
                issue_id       => $issue->issue_id,
2084
                itemnumber     => $item->{itemnumber},
2085
                borrowernumber => $patron->borrowernumber,
2086
                amount         => $fine,
2087
                due            => output_pref($ten_days_ago)
2088
            }
2089
        );
2090
        is( int( $patron->account->balance() ),
2091
            10, "Overdue fine of 10 days overdue" );
2092
2093
        # Fake longoverdue with charge and not marking returned
2094
        LostItem( $item->{itemnumber}, 'cronjob', 0 );
2095
        is( int( $patron->account->balance() ),
2096
            17, "Lost fine of 7 plus 10 days overdue" );
2097
2098
        # Now we return it today
2099
        AddReturn( $item->{barcode}, $library->{branchcode} );
2100
        is( int( $patron->account->balance() ),
2101
            17, "Should have a single 10 days overdue fine and lost charge" );
2102
      }
2090
};
2103
};
2091
2104
2092
subtest '_FixAccountForLostAndReturned' => sub {
2105
subtest '_FixAccountForLostAndReturned' => sub {
2093
- 

Return to bug 22877