|
Lines 2172-2178
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
| 2172 |
}; |
2172 |
}; |
| 2173 |
}; |
2173 |
}; |
| 2174 |
|
2174 |
|
| 2175 |
subtest '_FixAccountForLostAndReturned' => sub { |
2175 |
subtest '_FixAccountForLostAndFound' => sub { |
| 2176 |
|
2176 |
|
| 2177 |
plan tests => 5; |
2177 |
plan tests => 5; |
| 2178 |
|
2178 |
|
|
Lines 2250-2263
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2250 |
); |
2250 |
); |
| 2251 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); |
2251 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); |
| 2252 |
|
2252 |
|
| 2253 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2253 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
| 2254 |
is( $credit_return_id, undef, 'No LOST_RETURN account line added' ); |
2254 |
is( $credit_return_id, undef, 'No LOST_FOUND account line added' ); |
| 2255 |
|
2255 |
|
| 2256 |
$lost_fee_line->discard_changes; # reload from DB |
2256 |
$lost_fee_line->discard_changes; # reload from DB |
| 2257 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2257 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
| 2258 |
is( $lost_fee_line->debit_type_code, |
2258 |
is( $lost_fee_line->debit_type_code, |
| 2259 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2259 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 2260 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2260 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
| 2261 |
|
2261 |
|
| 2262 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2262 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
| 2263 |
}; |
2263 |
}; |
|
Lines 2312-2331
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2312 |
); |
2312 |
); |
| 2313 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
2313 |
$credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } ); |
| 2314 |
|
2314 |
|
| 2315 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2315 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
| 2316 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2316 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
| 2317 |
|
2317 |
|
| 2318 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2318 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
| 2319 |
is( $credit_return->amount + 0, |
2319 |
is( $credit_return->amount + 0, |
| 2320 |
-99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2320 |
-99.00, 'The account line of type LOST_FOUND has an amount of -99' ); |
| 2321 |
is( $credit_return->amountoutstanding + 0, |
2321 |
is( $credit_return->amountoutstanding + 0, |
| 2322 |
-99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' ); |
2322 |
-99.00, 'The account line of type LOST_FOUND has an amountoutstanding of -99' ); |
| 2323 |
|
2323 |
|
| 2324 |
$lost_fee_line->discard_changes; |
2324 |
$lost_fee_line->discard_changes; |
| 2325 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2325 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
| 2326 |
is( $lost_fee_line->debit_type_code, |
2326 |
is( $lost_fee_line->debit_type_code, |
| 2327 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2327 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 2328 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2328 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
| 2329 |
|
2329 |
|
| 2330 |
is( $patron->account->balance, |
2330 |
is( $patron->account->balance, |
| 2331 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
2331 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
|
Lines 2370-2387
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2370 |
is( $lost_fee_line->amountoutstanding + 0, |
2370 |
is( $lost_fee_line->amountoutstanding + 0, |
| 2371 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2371 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
| 2372 |
|
2372 |
|
| 2373 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2373 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
| 2374 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2374 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
| 2375 |
|
2375 |
|
| 2376 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2376 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
| 2377 |
is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2377 |
is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_FOUND has an amount of -99' ); |
| 2378 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' ); |
2378 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_FOUND has an amountoutstanding of 0' ); |
| 2379 |
|
2379 |
|
| 2380 |
$lost_fee_line->discard_changes; |
2380 |
$lost_fee_line->discard_changes; |
| 2381 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2381 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
| 2382 |
is( $lost_fee_line->debit_type_code, |
2382 |
is( $lost_fee_line->debit_type_code, |
| 2383 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2383 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 2384 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2384 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
| 2385 |
|
2385 |
|
| 2386 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2386 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
| 2387 |
}; |
2387 |
}; |
|
Lines 2456-2480
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2456 |
$lost_fee_line->discard_changes; |
2456 |
$lost_fee_line->discard_changes; |
| 2457 |
my $outstanding = $lost_fee_line->amountoutstanding; |
2457 |
my $outstanding = $lost_fee_line->amountoutstanding; |
| 2458 |
|
2458 |
|
| 2459 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2459 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item->itemnumber, $patron->id ); |
| 2460 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2460 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
| 2461 |
|
2461 |
|
| 2462 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_RETURN)' ); |
2462 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PROCESSING - PAYMENT (LOST_FOUND)' ); |
| 2463 |
|
2463 |
|
| 2464 |
$lost_fee_line->discard_changes; |
2464 |
$lost_fee_line->discard_changes; |
| 2465 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2465 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
| 2466 |
is( $lost_fee_line->debit_type_code, |
2466 |
is( $lost_fee_line->debit_type_code, |
| 2467 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2467 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 2468 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2468 |
is( $lost_fee_line->status, 'FOUND', "Lost fee now has account status of FOUND"); |
| 2469 |
|
2469 |
|
| 2470 |
is( $credit_return->credit_type_code, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2470 |
is( $credit_return->credit_type_code, 'LOST_FOUND', 'An account line of type LOST_FOUND is added' ); |
| 2471 |
is( $credit_return->amount + 0, |
2471 |
is( $credit_return->amount + 0, |
| 2472 |
($payment_amount + $outstanding ) * -1, |
2472 |
($payment_amount + $outstanding ) * -1, |
| 2473 |
'The account line of type LOST_RETURN has an amount equal to the payment + outstanding' |
2473 |
'The account line of type LOST_FOUND has an amount equal to the payment + outstanding' |
| 2474 |
); |
2474 |
); |
| 2475 |
is( $credit_return->amountoutstanding + 0, |
2475 |
is( $credit_return->amountoutstanding + 0, |
| 2476 |
$payment_amount * -1, |
2476 |
$payment_amount * -1, |
| 2477 |
'The account line of type LOST_RETURN has an amountoutstanding equal to the payment' |
2477 |
'The account line of type LOST_FOUND has an amountoutstanding equal to the payment' |
| 2478 |
); |
2478 |
); |
| 2479 |
|
2479 |
|
| 2480 |
is( $account->balance, |
2480 |
is( $account->balance, |
|
Lines 2552-2561
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2552 |
|
2552 |
|
| 2553 |
t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 ); |
2553 |
t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 ); |
| 2554 |
|
2554 |
|
| 2555 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id ); |
2555 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndFound( $item_id, $patron->id ); |
| 2556 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2556 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
| 2557 |
|
2557 |
|
| 2558 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_RETURN)' ); |
2558 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PROCESSING - payment (LOST_FOUND)' ); |
| 2559 |
|
2559 |
|
| 2560 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next; |
2560 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next; |
| 2561 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
2561 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
|
Lines 2647-2653
subtest '_FixOverduesOnReturn' => sub {
Link Here
|
| 2647 |
is( $accountline->status, 'RETURNED', 'Passed status has been used to set as RETURNED )'); |
2647 |
is( $accountline->status, 'RETURNED', 'Passed status has been used to set as RETURNED )'); |
| 2648 |
}; |
2648 |
}; |
| 2649 |
|
2649 |
|
| 2650 |
subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => sub { |
2650 |
subtest '_FixAccountForLostAndFound returns undef if patron is deleted' => sub { |
| 2651 |
plan tests => 1; |
2651 |
plan tests => 1; |
| 2652 |
|
2652 |
|
| 2653 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
2653 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
|
Lines 2683-2691
subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => su
Link Here
|
| 2683 |
|
2683 |
|
| 2684 |
$patron->delete(); |
2684 |
$patron->delete(); |
| 2685 |
|
2685 |
|
| 2686 |
my $return_value = C4::Circulation::_FixAccountForLostAndReturned( $patron->id, $item->itemnumber ); |
2686 |
my $return_value = C4::Circulation::_FixAccountForLostAndFound( $patron->id, $item->itemnumber ); |
| 2687 |
|
2687 |
|
| 2688 |
is( $return_value, undef, "_FixAccountForLostAndReturned returns undef if patron is deleted" ); |
2688 |
is( $return_value, undef, "_FixAccountForLostAndFound returns undef if patron is deleted" ); |
| 2689 |
|
2689 |
|
| 2690 |
}; |
2690 |
}; |
| 2691 |
|
2691 |
|
| 2692 |
- |
|
|