Lines 22-27
use Test::More tests => 48;
Link Here
|
22 |
use Test::Exception; |
22 |
use Test::Exception; |
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
24 |
use Test::Deep qw( cmp_deeply ); |
24 |
use Test::Deep qw( cmp_deeply ); |
|
|
25 |
use Test::Warn; |
25 |
|
26 |
|
26 |
use Data::Dumper; |
27 |
use Data::Dumper; |
27 |
use DateTime; |
28 |
use DateTime; |
Lines 2409-2415
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2409 |
is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); |
2410 |
is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); |
2410 |
Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; |
2411 |
Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; |
2411 |
|
2412 |
|
2412 |
subtest 'bug 22877' => sub { |
2413 |
subtest 'bug 22877 | Lost item return' => sub { |
2413 |
|
2414 |
|
2414 |
plan tests => 3; |
2415 |
plan tests => 3; |
2415 |
|
2416 |
|
Lines 2659-2664
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2659 |
}; |
2660 |
}; |
2660 |
}; |
2661 |
}; |
2661 |
|
2662 |
|
|
|
2663 |
subtest '_RestoreOverdueForLostAndFound' => sub { |
2664 |
|
2665 |
plan tests => 7; |
2666 |
|
2667 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
2668 |
t::lib::Mocks::mock_userenv( |
2669 |
{ patron => $manager, branchcode => $manager->branchcode } ); |
2670 |
|
2671 |
my $patron = $builder->build_object( { class => "Koha::Patrons" } ); |
2672 |
my $item = $builder->build_sample_item(); |
2673 |
|
2674 |
# No fine found |
2675 |
my $result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber); |
2676 |
is($result, 0, "0 returned when no overdue found"); |
2677 |
|
2678 |
# Fine not forgiven |
2679 |
my $account = $patron->account; |
2680 |
my $overdue = $account->add_debit( |
2681 |
{ |
2682 |
amount => 30.00, |
2683 |
user_id => $manager->borrowernumber, |
2684 |
library_id => $library2->{branchcode}, |
2685 |
interface => 'test', |
2686 |
item_id => $item->itemnumber, |
2687 |
type => 'OVERDUE', |
2688 |
} |
2689 |
)->store(); |
2690 |
$overdue->status('LOST')->store(); |
2691 |
|
2692 |
$result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber); |
2693 |
is($result, 0, "0 returned when overdue found without forgival"); |
2694 |
$overdue->discard_changes; |
2695 |
is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED'); |
2696 |
|
2697 |
# Reset status |
2698 |
$overdue->status('LOST')->store(); |
2699 |
|
2700 |
# Fine forgiven |
2701 |
my $credit = $account->add_credit( |
2702 |
{ |
2703 |
amount => 30.00, |
2704 |
user_id => $manager->borrowernumber, |
2705 |
library_id => $library2->{branchcode}, |
2706 |
interface => 'test', |
2707 |
type => 'FORGIVEN', |
2708 |
item_id => $item->itemnumber |
2709 |
} |
2710 |
); |
2711 |
$credit->apply( { debits => [$overdue], offset_type => 'Forgiven' } ); |
2712 |
|
2713 |
$result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber); |
2714 |
|
2715 |
is( ref($result), 'Koha::Account::Line', 'Return a Koha::Account::Line object on sucess'); |
2716 |
$overdue->discard_changes; |
2717 |
is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED'); |
2718 |
is($overdue->amountoutstanding, $overdue->amount, 'Overdue outstanding restored'); |
2719 |
|
2720 |
# Missing parameters |
2721 |
warning_like { |
2722 |
C4::Circulation::_RestoreOverdueForLostAndFound( undef ) |
2723 |
} |
2724 |
qr/_RestoreOverdueForLostAndFound\(\) not supplied valid itemnumber/, |
2725 |
"parameter warning received for missing itemnumbernumber"; |
2726 |
}; |
2727 |
|
2662 |
subtest '_FixOverduesOnReturn' => sub { |
2728 |
subtest '_FixOverduesOnReturn' => sub { |
2663 |
plan tests => 14; |
2729 |
plan tests => 14; |
2664 |
|
2730 |
|
Lines 2717-2723
subtest '_FixOverduesOnReturn' => sub {
Link Here
|
2717 |
|
2783 |
|
2718 |
is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' ); |
2784 |
is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' ); |
2719 |
isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )'); |
2785 |
isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )'); |
2720 |
is( $accountline->status, 'FORGIVEN', 'Open fine ( account type OVERDUE ) has been set to fine forgiven ( status FORGIVEN )'); |
2786 |
is( $accountline->status, 'RETURNED', 'Open fine ( account type OVERDUE ) has been set to returned ( status RETURNED )'); |
2721 |
is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" ); |
2787 |
is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" ); |
2722 |
is( $offset->amount + 0, -99, "Amount of offset is correct" ); |
2788 |
is( $offset->amount + 0, -99, "Amount of offset is correct" ); |
2723 |
my $credit = $offset->credit; |
2789 |
my $credit = $offset->credit; |
2724 |
- |
|
|