Lines 2409-2415
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2409 |
} |
2409 |
} |
2410 |
}; |
2410 |
}; |
2411 |
|
2411 |
|
2412 |
subtest '_FixAccountForLostAndReturned' => sub { |
2412 |
subtest '_FixAccountForLostAndFound' => sub { |
2413 |
|
2413 |
|
2414 |
plan tests => 5; |
2414 |
plan tests => 5; |
2415 |
|
2415 |
|
Lines 2487-2500
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2487 |
); |
2487 |
); |
2488 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); |
2488 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); |
2489 |
|
2489 |
|
2490 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2490 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
2491 |
is( $credit_return_id, undef, 'No LOST_RETURN account line added' ); |
2491 |
is( $credit_return_id, undef, 'No LOST_FOUND account line added' ); |
2492 |
|
2492 |
|
2493 |
$lost_fee_line->discard_changes; # reload from DB |
2493 |
$lost_fee_line->discard_changes; # reload from DB |
2494 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2494 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2495 |
is( $lost_fee_line->debit_type_code, |
2495 |
is( $lost_fee_line->debit_type_code, |
2496 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2496 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2497 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2497 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
2498 |
|
2498 |
|
2499 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2499 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2500 |
}; |
2500 |
}; |
Lines 2549-2568
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2549 |
); |
2549 |
); |
2550 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
2550 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
2551 |
|
2551 |
|
2552 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2552 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
2553 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2553 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2554 |
|
2554 |
|
2555 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2555 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
2556 |
is( $credit_return->amount + 0, |
2556 |
is( $credit_return->amount + 0, |
2557 |
-99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2557 |
-99.00, 'The account line of type LOST_FOUND has an amount of -99' ); |
2558 |
is( $credit_return->amountoutstanding + 0, |
2558 |
is( $credit_return->amountoutstanding + 0, |
2559 |
-99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' ); |
2559 |
-99.00, 'The account line of type LOST_FOUND has an amountoutstanding of -99' ); |
2560 |
|
2560 |
|
2561 |
$lost_fee_line->discard_changes; |
2561 |
$lost_fee_line->discard_changes; |
2562 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2562 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2563 |
is( $lost_fee_line->debit_type_code, |
2563 |
is( $lost_fee_line->debit_type_code, |
2564 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2564 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2565 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2565 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
2566 |
|
2566 |
|
2567 |
is( $patron->account->balance, |
2567 |
is( $patron->account->balance, |
2568 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
2568 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
Lines 2607-2624
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2607 |
is( $lost_fee_line->amountoutstanding + 0, |
2607 |
is( $lost_fee_line->amountoutstanding + 0, |
2608 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2608 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2609 |
|
2609 |
|
2610 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2610 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
2611 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2611 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2612 |
|
2612 |
|
2613 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2613 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
2614 |
is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2614 |
is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_FOUND has an amount of -99' ); |
2615 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' ); |
2615 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_FOUND has an amountoutstanding of 0' ); |
2616 |
|
2616 |
|
2617 |
$lost_fee_line->discard_changes; |
2617 |
$lost_fee_line->discard_changes; |
2618 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2618 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2619 |
is( $lost_fee_line->debit_type_code, |
2619 |
is( $lost_fee_line->debit_type_code, |
2620 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2620 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2621 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2621 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
2622 |
|
2622 |
|
2623 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2623 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2624 |
}; |
2624 |
}; |
Lines 2693-2717
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2693 |
$lost_fee_line->discard_changes; |
2693 |
$lost_fee_line->discard_changes; |
2694 |
my $outstanding = $lost_fee_line->amountoutstanding; |
2694 |
my $outstanding = $lost_fee_line->amountoutstanding; |
2695 |
|
2695 |
|
2696 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2696 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
2697 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2697 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2698 |
|
2698 |
|
2699 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_RETURN)' ); |
2699 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_FOUND)' ); |
2700 |
|
2700 |
|
2701 |
$lost_fee_line->discard_changes; |
2701 |
$lost_fee_line->discard_changes; |
2702 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2702 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2703 |
is( $lost_fee_line->debit_type_code, |
2703 |
is( $lost_fee_line->debit_type_code, |
2704 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2704 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2705 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2705 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
2706 |
|
2706 |
|
2707 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2707 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
2708 |
is( $credit_return->amount + 0, |
2708 |
is( $credit_return->amount + 0, |
2709 |
($payment_amount + $outstanding ) * -1, |
2709 |
($payment_amount + $outstanding ) * -1, |
2710 |
'The account line of type LOST_RETURN has an amount equal to the payment + outstanding' |
2710 |
'The account line of type LOST_FOUND has an amount equal to the payment + outstanding' |
2711 |
); |
2711 |
); |
2712 |
is( $credit_return->amountoutstanding + 0, |
2712 |
is( $credit_return->amountoutstanding + 0, |
2713 |
$payment_amount * -1, |
2713 |
$payment_amount * -1, |
2714 |
'The account line of type LOST_RETURN has an amountoutstanding equal to the payment' |
2714 |
'The account line of type LOST_FOUND has an amountoutstanding equal to the payment' |
2715 |
); |
2715 |
); |
2716 |
|
2716 |
|
2717 |
is( $account->balance, |
2717 |
is( $account->balance, |
Lines 2789-2798
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2789 |
|
2789 |
|
2790 |
t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 ); |
2790 |
t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 ); |
2791 |
|
2791 |
|
2792 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id ); |
2792 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item_id, $patron->id ); |
2793 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2793 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2794 |
|
2794 |
|
2795 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_RETURN)' ); |
2795 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_FOUND)' ); |
2796 |
|
2796 |
|
2797 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next; |
2797 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next; |
2798 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
2798 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
Lines 2866-2872
subtest '_FixOverduesOnReturn' => sub {
Link Here
|
2866 |
is( $credit->amountoutstanding + 0, 0, "Credit amountoutstanding is correctly set to 0" ); |
2866 |
is( $credit->amountoutstanding + 0, 0, "Credit amountoutstanding is correctly set to 0" ); |
2867 |
}; |
2867 |
}; |
2868 |
|
2868 |
|
2869 |
subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => sub { |
2869 |
subtest '_FixAccountForLostAndFound returns undef if patron is deleted' => sub { |
2870 |
plan tests => 1; |
2870 |
plan tests => 1; |
2871 |
|
2871 |
|
2872 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
2872 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
Lines 2902-2910
subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => su
Link Here
|
2902 |
|
2902 |
|
2903 |
$patron->delete(); |
2903 |
$patron->delete(); |
2904 |
|
2904 |
|
2905 |
my $return_value = C4::Circulation::_FixAccountForLostAndReturned( $patron->id, $item->itemnumber ); |
2905 |
my $return_value = C4::Circulation::_FixAccountForLostAndFound( $patron->id, $item->itemnumber ); |
2906 |
|
2906 |
|
2907 |
is( $return_value, undef, "_FixAccountForLostAndReturned returns undef if patron is deleted" ); |
2907 |
is( $return_value, undef, "_FixAccountForLostAndFound returns undef if patron is deleted" ); |
2908 |
|
2908 |
|
2909 |
}; |
2909 |
}; |
2910 |
|
2910 |
|
2911 |
- |
|
|