Lines 18-26
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use utf8; |
19 |
use utf8; |
20 |
|
20 |
|
21 |
use Test::More tests => 48; |
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 2413-2419
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2413 |
is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); |
2414 |
is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); |
2414 |
Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; |
2415 |
Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; |
2415 |
|
2416 |
|
2416 |
subtest 'bug 22877' => sub { |
2417 |
subtest 'bug 22877 | Lost item return' => sub { |
2417 |
|
2418 |
|
2418 |
plan tests => 3; |
2419 |
plan tests => 3; |
2419 |
|
2420 |
|
Lines 2880-2885
subtest '_FixAccountForLostAndFound' => sub {
Link Here
|
2880 |
}; |
2881 |
}; |
2881 |
}; |
2882 |
}; |
2882 |
|
2883 |
|
|
|
2884 |
subtest '_RestoreOverdueForLostAndFound' => sub { |
2885 |
|
2886 |
plan tests => 8; |
2887 |
|
2888 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
2889 |
t::lib::Mocks::mock_userenv( |
2890 |
{ patron => $manager, branchcode => $manager->branchcode } ); |
2891 |
|
2892 |
my $patron = $builder->build_object( { class => "Koha::Patrons" } ); |
2893 |
my $item = $builder->build_sample_item(); |
2894 |
|
2895 |
# No fine found |
2896 |
my $result = C4::Circulation::_RestoreOverdueForLostAndFound($patron->borrowernumber, $item->itemnumber); |
2897 |
is($result, 0, "0 returned when no overdue found"); |
2898 |
|
2899 |
# Fine not forgiven |
2900 |
my $account = $patron->account; |
2901 |
my $overdue = $account->add_debit( |
2902 |
{ |
2903 |
amount => 30.00, |
2904 |
user_id => $manager->borrowernumber, |
2905 |
library_id => $library2->{branchcode}, |
2906 |
interface => 'test', |
2907 |
item_id => $item->itemnumber, |
2908 |
type => 'OVERDUE', |
2909 |
} |
2910 |
)->store(); |
2911 |
$overdue->status('LOST')->store(); |
2912 |
|
2913 |
$result = C4::Circulation::_RestoreOverdueForLostAndFound($patron->borrowernumber, $item->itemnumber); |
2914 |
is($result, 0, "0 returned when overdue found without forgival"); |
2915 |
$overdue->discard_changes; |
2916 |
is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED'); |
2917 |
|
2918 |
# Reset status |
2919 |
$overdue->status('LOST')->store(); |
2920 |
|
2921 |
# Fine forgiven |
2922 |
my $credit = $account->add_credit( |
2923 |
{ |
2924 |
amount => 30.00, |
2925 |
user_id => $manager->borrowernumber, |
2926 |
library_id => $library2->{branchcode}, |
2927 |
interface => 'test', |
2928 |
type => 'FORGIVEN', |
2929 |
item_id => $item->itemnumber |
2930 |
} |
2931 |
); |
2932 |
$credit->apply( { debits => [$overdue], offset_type => 'Forgiven' } ); |
2933 |
|
2934 |
$result = C4::Circulation::_RestoreOverdueForLostAndFound($patron->borrowernumber, $item->itemnumber); |
2935 |
|
2936 |
is( ref($result), 'Koha::Account::Line', 'Return a Koha::Account::Line object on sucess'); |
2937 |
$overdue->discard_changes; |
2938 |
is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED'); |
2939 |
is($overdue->amountoutstanding, $overdue->amount, 'Overdue outstanding restored'); |
2940 |
|
2941 |
# Missing parameters |
2942 |
warning_like { |
2943 |
C4::Circulation::_RestoreOverdueForLostAndFound( undef, |
2944 |
$item->itemnumber ) |
2945 |
} |
2946 |
qr/_RestoreOverdueForLostAndFound\(\) not supplied valid borrowernumber/, |
2947 |
"parameter warning received for missing borrowernumber"; |
2948 |
|
2949 |
warning_like { |
2950 |
C4::Circulation::_RestoreOverdueForLostAndFound( |
2951 |
$patron->borrowernumber, undef ) |
2952 |
} |
2953 |
qr/_RestoreOverdueForLostAndFound\(\) not supplied valid itemnumber/, |
2954 |
"parameter warning received for missing itemnumbernumber"; |
2955 |
|
2956 |
}; |
2957 |
|
2883 |
subtest '_FixOverduesOnReturn' => sub { |
2958 |
subtest '_FixOverduesOnReturn' => sub { |
2884 |
plan tests => 14; |
2959 |
plan tests => 14; |
2885 |
|
2960 |
|
Lines 2938-2944
subtest '_FixOverduesOnReturn' => sub {
Link Here
|
2938 |
|
3013 |
|
2939 |
is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' ); |
3014 |
is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' ); |
2940 |
isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )'); |
3015 |
isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )'); |
2941 |
is( $accountline->status, 'FORGIVEN', 'Open fine ( account type OVERDUE ) has been set to fine forgiven ( status FORGIVEN )'); |
3016 |
is( $accountline->status, 'RETURNED', 'Open fine ( account type OVERDUE ) has been set to returned ( status RETURNED )'); |
2942 |
is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" ); |
3017 |
is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" ); |
2943 |
is( $offset->amount + 0, -99, "Amount of offset is correct" ); |
3018 |
is( $offset->amount + 0, -99, "Amount of offset is correct" ); |
2944 |
my $credit = $offset->credit; |
3019 |
my $credit = $offset->credit; |
2945 |
- |
|
|