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

(-)a/t/db_dependent/Circulation.t (-3 / +77 lines)
Lines 21-26 use utf8; Link Here
21
use Test::More tests => 49;
21
use Test::More tests => 49;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Deep qw( cmp_deeply );
23
use Test::Deep qw( cmp_deeply );
24
use Test::Warn;
24
25
25
use Data::Dumper;
26
use Data::Dumper;
26
use DateTime;
27
use DateTime;
Lines 2418-2424 subtest 'AddReturn | is_overdue' => sub { Link Here
2418
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2419
    is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
2419
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2420
    Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
2420
2421
2421
    subtest 'bug 22877' => sub {
2422
    subtest 'bug 22877 | Lost item return' => sub {
2422
2423
2423
        plan tests => 3;
2424
        plan tests => 3;
2424
2425
Lines 3059-3064 subtest '_FixAccountForLostAndFound' => sub { Link Here
3059
    };
3060
    };
3060
};
3061
};
3061
3062
3063
subtest '_RestoreOverdueForLostAndFound' => sub {
3064
3065
    plan tests => 8;
3066
3067
    my $manager = $builder->build_object( { class => "Koha::Patrons" } );
3068
    t::lib::Mocks::mock_userenv(
3069
        { patron => $manager, branchcode => $manager->branchcode } );
3070
3071
    my $patron = $builder->build_object( { class => "Koha::Patrons" } );
3072
    my $item = $builder->build_sample_item();
3073
3074
    # No fine found
3075
    my $result = C4::Circulation::_RestoreOverdueForLostAndFound($patron->borrowernumber, $item->itemnumber);
3076
    is($result, 0, "0 returned when no overdue found");
3077
3078
    # Fine not forgiven
3079
    my $account = $patron->account;
3080
    my $overdue = $account->add_debit(
3081
        {
3082
            amount     => 30.00,
3083
            user_id    => $manager->borrowernumber,
3084
            library_id => $library2->{branchcode},
3085
            interface  => 'test',
3086
            item_id    => $item->itemnumber,
3087
            type       => 'OVERDUE',
3088
        }
3089
    )->store();
3090
    $overdue->status('LOST')->store();
3091
3092
    $result = C4::Circulation::_RestoreOverdueForLostAndFound($patron->borrowernumber, $item->itemnumber);
3093
    is($result, 0, "0 returned when overdue found without forgival");
3094
    $overdue->discard_changes;
3095
    is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED');
3096
3097
    # Reset status
3098
    $overdue->status('LOST')->store();
3099
3100
    # Fine forgiven
3101
    my $credit = $account->add_credit(
3102
        {
3103
            amount     => 30.00,
3104
            user_id    => $manager->borrowernumber,
3105
            library_id => $library2->{branchcode},
3106
            interface  => 'test',
3107
            type       => 'FORGIVEN',
3108
            item_id    => $item->itemnumber
3109
        }
3110
    );
3111
    $credit->apply( { debits => [$overdue], offset_type => 'Forgiven' } );
3112
3113
    $result = C4::Circulation::_RestoreOverdueForLostAndFound($patron->borrowernumber, $item->itemnumber);
3114
3115
    is( ref($result), 'Koha::Account::Line', 'Return a Koha::Account::Line object on sucess');
3116
    $overdue->discard_changes;
3117
    is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED');
3118
    is($overdue->amountoutstanding, $overdue->amount, 'Overdue outstanding restored');
3119
3120
    # Missing parameters
3121
    warning_like {
3122
        C4::Circulation::_RestoreOverdueForLostAndFound( undef,
3123
            $item->itemnumber )
3124
    }
3125
    qr/_RestoreOverdueForLostAndFound\(\) not supplied valid borrowernumber/,
3126
      "parameter warning received for missing borrowernumber";
3127
3128
    warning_like {
3129
        C4::Circulation::_RestoreOverdueForLostAndFound(
3130
            $patron->borrowernumber, undef )
3131
    }
3132
    qr/_RestoreOverdueForLostAndFound\(\) not supplied valid itemnumber/,
3133
      "parameter warning received for missing itemnumbernumber";
3134
3135
};
3136
3062
subtest '_FixOverduesOnReturn' => sub {
3137
subtest '_FixOverduesOnReturn' => sub {
3063
    plan tests => 14;
3138
    plan tests => 14;
3064
3139
Lines 3117-3123 subtest '_FixOverduesOnReturn' => sub { Link Here
3117
3192
3118
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
3193
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
3119
    isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )');
3194
    isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )');
3120
    is( $accountline->status, 'FORGIVEN', 'Open fine ( account type OVERDUE ) has been set to fine forgiven ( status FORGIVEN )');
3195
    is( $accountline->status, 'RETURNED', 'Open fine ( account type OVERDUE ) has been set to returned ( status RETURNED )');
3121
    is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" );
3196
    is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" );
3122
    is( $offset->amount + 0, -99, "Amount of offset is correct" );
3197
    is( $offset->amount + 0, -99, "Amount of offset is correct" );
3123
    my $credit = $offset->credit;
3198
    my $credit = $offset->credit;
3124
- 

Return to bug 23091