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

(-)a/t/db_dependent/Circulation.t (-26 / +35 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 => 7;
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
2062
    AddReturn( $item->{barcode}, $library->{branchcode}, $ten_days_ago );
2063
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2064
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2065
2066
    # specify dropbox date 5 days later => overdue, or... not
2067
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2061
    AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2068
    AddReturn( $item->{barcode}, $library->{branchcode}, $five_days_ago );
2062
    AddReturn( $item->{barcode}, $library->{branchcode}, 1, $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
2063
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2070
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2064
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2071
2065
2072
    # Checkout an item 10 days ago
2066
    subtest 'bug 22877' => sub {
2073
    my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
2067
        my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago );    # date due was 10d ago
2074
    # Fake fines cronjob on this checkout
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
2068
2069
        # Fake fines cronjob on this checkout
2070
        my ($fine) =
2071
          CalcFine( $item, $patron->categorycode, $library->{branchcode},
2072
            $ten_days_ago, $now );
2073
        UpdateFine(
2074
            {
2075
                issue_id       => $issue->issue_id,
2076
                itemnumber     => $item->{itemnumber},
2077
                borrowernumber => $patron->borrowernumber,
2078
                amount         => $fine,
2079
                due            => output_pref($ten_days_ago)
2080
            }
2081
        );
2082
        is( int( $patron->account->balance() ),
2083
            10, "Overdue fine of 10 days overdue" );
2084
2085
        # Fake longoverdue with charge and not marking returned
2086
        LostItem( $item->{itemnumber}, 'cronjob', 0 );
2087
        is( int( $patron->account->balance() ),
2088
            17, "Lost fine of 7 plus 10 days overdue" );
2089
2090
        # Now we return it today
2091
        AddReturn( $item->{barcode}, $library->{branchcode} );
2092
        is( int( $patron->account->balance() ),
2093
            17, "Should have a single 10 days overdue fine and lost charge" );
2094
      }
2085
};
2095
};
2086
2096
2087
subtest '_FixAccountForLostAndReturned' => sub {
2097
subtest '_FixAccountForLostAndReturned' => sub {
2088
- 

Return to bug 22877