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

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

Return to bug 22877