Lines 2346-2352
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2346 |
} |
2346 |
} |
2347 |
}; |
2347 |
}; |
2348 |
|
2348 |
|
2349 |
subtest '_FixAccountForLostAndReturned' => sub { |
2349 |
subtest '_FixAccountForLostAndFound' => sub { |
2350 |
|
2350 |
|
2351 |
plan tests => 5; |
2351 |
plan tests => 5; |
2352 |
|
2352 |
|
Lines 2424-2437
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2424 |
); |
2424 |
); |
2425 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); |
2425 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); |
2426 |
|
2426 |
|
2427 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2427 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
2428 |
is( $credit_return_id, undef, 'No LOST_RETURN account line added' ); |
2428 |
is( $credit_return_id, undef, 'No LOST_FOUND account line added' ); |
2429 |
|
2429 |
|
2430 |
$lost_fee_line->discard_changes; # reload from DB |
2430 |
$lost_fee_line->discard_changes; # reload from DB |
2431 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2431 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2432 |
is( $lost_fee_line->debit_type_code, |
2432 |
is( $lost_fee_line->debit_type_code, |
2433 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2433 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2434 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2434 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
2435 |
|
2435 |
|
2436 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2436 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2437 |
}; |
2437 |
}; |
Lines 2486-2505
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2486 |
); |
2486 |
); |
2487 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
2487 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
2488 |
|
2488 |
|
2489 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2489 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
2490 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2490 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2491 |
|
2491 |
|
2492 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2492 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
2493 |
is( $credit_return->amount + 0, |
2493 |
is( $credit_return->amount + 0, |
2494 |
-99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2494 |
-99.00, 'The account line of type LOST_FOUND has an amount of -99' ); |
2495 |
is( $credit_return->amountoutstanding + 0, |
2495 |
is( $credit_return->amountoutstanding + 0, |
2496 |
-99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' ); |
2496 |
-99.00, 'The account line of type LOST_FOUND has an amountoutstanding of -99' ); |
2497 |
|
2497 |
|
2498 |
$lost_fee_line->discard_changes; |
2498 |
$lost_fee_line->discard_changes; |
2499 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2499 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2500 |
is( $lost_fee_line->debit_type_code, |
2500 |
is( $lost_fee_line->debit_type_code, |
2501 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2501 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2502 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2502 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
2503 |
|
2503 |
|
2504 |
is( $patron->account->balance, |
2504 |
is( $patron->account->balance, |
2505 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
2505 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
Lines 2544-2561
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2544 |
is( $lost_fee_line->amountoutstanding + 0, |
2544 |
is( $lost_fee_line->amountoutstanding + 0, |
2545 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2545 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2546 |
|
2546 |
|
2547 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2547 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
2548 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2548 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2549 |
|
2549 |
|
2550 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2550 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
2551 |
is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2551 |
is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_FOUND has an amount of -99' ); |
2552 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' ); |
2552 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_FOUND has an amountoutstanding of 0' ); |
2553 |
|
2553 |
|
2554 |
$lost_fee_line->discard_changes; |
2554 |
$lost_fee_line->discard_changes; |
2555 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2555 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2556 |
is( $lost_fee_line->debit_type_code, |
2556 |
is( $lost_fee_line->debit_type_code, |
2557 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2557 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2558 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2558 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
2559 |
|
2559 |
|
2560 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2560 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2561 |
}; |
2561 |
}; |
Lines 2630-2654
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2630 |
$lost_fee_line->discard_changes; |
2630 |
$lost_fee_line->discard_changes; |
2631 |
my $outstanding = $lost_fee_line->amountoutstanding; |
2631 |
my $outstanding = $lost_fee_line->amountoutstanding; |
2632 |
|
2632 |
|
2633 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2633 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
2634 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2634 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2635 |
|
2635 |
|
2636 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_RETURN)' ); |
2636 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_FOUND)' ); |
2637 |
|
2637 |
|
2638 |
$lost_fee_line->discard_changes; |
2638 |
$lost_fee_line->discard_changes; |
2639 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2639 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2640 |
is( $lost_fee_line->debit_type_code, |
2640 |
is( $lost_fee_line->debit_type_code, |
2641 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2641 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2642 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2642 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
2643 |
|
2643 |
|
2644 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2644 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
2645 |
is( $credit_return->amount + 0, |
2645 |
is( $credit_return->amount + 0, |
2646 |
($payment_amount + $outstanding ) * -1, |
2646 |
($payment_amount + $outstanding ) * -1, |
2647 |
'The account line of type LOST_RETURN has an amount equal to the payment + outstanding' |
2647 |
'The account line of type LOST_FOUND has an amount equal to the payment + outstanding' |
2648 |
); |
2648 |
); |
2649 |
is( $credit_return->amountoutstanding + 0, |
2649 |
is( $credit_return->amountoutstanding + 0, |
2650 |
$payment_amount * -1, |
2650 |
$payment_amount * -1, |
2651 |
'The account line of type LOST_RETURN has an amountoutstanding equal to the payment' |
2651 |
'The account line of type LOST_FOUND has an amountoutstanding equal to the payment' |
2652 |
); |
2652 |
); |
2653 |
|
2653 |
|
2654 |
is( $account->balance, |
2654 |
is( $account->balance, |
Lines 2726-2735
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2726 |
|
2726 |
|
2727 |
t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 ); |
2727 |
t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 ); |
2728 |
|
2728 |
|
2729 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id ); |
2729 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item_id, $patron->id ); |
2730 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2730 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2731 |
|
2731 |
|
2732 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_RETURN)' ); |
2732 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_FOUND)' ); |
2733 |
|
2733 |
|
2734 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next; |
2734 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next; |
2735 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
2735 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
Lines 2803-2809
subtest '_FixOverduesOnReturn' => sub {
Link Here
|
2803 |
is( $credit->amountoutstanding + 0, 0, "Credit amountoutstanding is correctly set to 0" ); |
2803 |
is( $credit->amountoutstanding + 0, 0, "Credit amountoutstanding is correctly set to 0" ); |
2804 |
}; |
2804 |
}; |
2805 |
|
2805 |
|
2806 |
subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => sub { |
2806 |
subtest '_FixAccountForLostAndFound returns undef if patron is deleted' => sub { |
2807 |
plan tests => 1; |
2807 |
plan tests => 1; |
2808 |
|
2808 |
|
2809 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
2809 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
Lines 2839-2847
subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => su
Link Here
|
2839 |
|
2839 |
|
2840 |
$patron->delete(); |
2840 |
$patron->delete(); |
2841 |
|
2841 |
|
2842 |
my $return_value = C4::Circulation::_FixAccountForLostAndReturned( $patron->id, $item->itemnumber ); |
2842 |
my $return_value = C4::Circulation::_FixAccountForLostAndFound( $patron->id, $item->itemnumber ); |
2843 |
|
2843 |
|
2844 |
is( $return_value, undef, "_FixAccountForLostAndReturned returns undef if patron is deleted" ); |
2844 |
is( $return_value, undef, "_FixAccountForLostAndFound returns undef if patron is deleted" ); |
2845 |
|
2845 |
|
2846 |
}; |
2846 |
}; |
2847 |
|
2847 |
|
2848 |
- |
|
|