Lines 2177-2183
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2177 |
|
2177 |
|
2178 |
subtest 'Full write-off tests' => sub { |
2178 |
subtest 'Full write-off tests' => sub { |
2179 |
|
2179 |
|
2180 |
plan tests => 10; |
2180 |
plan tests => 12; |
2181 |
|
2181 |
|
2182 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2182 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2183 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
2183 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
Lines 2211-2219
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2211 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2211 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2212 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2212 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2213 |
my $lost_fee_line = $lost_fee_lines->next; |
2213 |
my $lost_fee_line = $lost_fee_lines->next; |
2214 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2214 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2215 |
is( $lost_fee_line->amountoutstanding + 0, |
2215 |
is( $lost_fee_line->amountoutstanding + 0, |
2216 |
$replacement_amount, 'The right L amountoutstanding is generated' ); |
2216 |
$replacement_amount, 'The right LOST amountoutstanding is generated' ); |
|
|
2217 |
is( $lost_fee_line->status, |
2218 |
undef, 'The LOST status was not set' ); |
2217 |
|
2219 |
|
2218 |
my $account = $patron->account; |
2220 |
my $account = $patron->account; |
2219 |
my $debts = $account->outstanding_debits; |
2221 |
my $debts = $account->outstanding_debits; |
Lines 2228-2246
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2228 |
$credit->apply( { debits => $debts, offset_type => 'Writeoff' } ); |
2230 |
$credit->apply( { debits => $debts, offset_type => 'Writeoff' } ); |
2229 |
|
2231 |
|
2230 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2232 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2231 |
is( $credit_return_id, undef, 'No CR account line added' ); |
2233 |
is( $credit_return_id, undef, 'No LOST_RETURN account line added' ); |
2232 |
|
2234 |
|
2233 |
$lost_fee_line->discard_changes; # reload from DB |
2235 |
$lost_fee_line->discard_changes; # reload from DB |
2234 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2236 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2235 |
is( $lost_fee_line->accounttype, |
2237 |
is( $lost_fee_line->accounttype, |
2236 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2238 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2239 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2237 |
|
2240 |
|
2238 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2241 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2239 |
}; |
2242 |
}; |
2240 |
|
2243 |
|
2241 |
subtest 'Full payment tests' => sub { |
2244 |
subtest 'Full payment tests' => sub { |
2242 |
|
2245 |
|
2243 |
plan tests => 12; |
2246 |
plan tests => 13; |
2244 |
|
2247 |
|
2245 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2248 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2246 |
|
2249 |
|
Lines 2272-2280
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2272 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2275 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2273 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2276 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2274 |
my $lost_fee_line = $lost_fee_lines->next; |
2277 |
my $lost_fee_line = $lost_fee_lines->next; |
2275 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2278 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2276 |
is( $lost_fee_line->amountoutstanding + 0, |
2279 |
is( $lost_fee_line->amountoutstanding + 0, |
2277 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2280 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2278 |
|
2281 |
|
2279 |
my $account = $patron->account; |
2282 |
my $account = $patron->account; |
2280 |
my $debts = $account->outstanding_debits; |
2283 |
my $debts = $account->outstanding_debits; |
Lines 2291-2306
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2291 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2294 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2292 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2295 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2293 |
|
2296 |
|
2294 |
is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' ); |
2297 |
is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2295 |
is( $credit_return->amount + 0, |
2298 |
is( $credit_return->amount + 0, |
2296 |
-99.00, 'The account line of type CR has an amount of -99' ); |
2299 |
-99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2297 |
is( $credit_return->amountoutstanding + 0, |
2300 |
is( $credit_return->amountoutstanding + 0, |
2298 |
-99.00, 'The account line of type CR has an amountoutstanding of -99' ); |
2301 |
-99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' ); |
2299 |
|
2302 |
|
2300 |
$lost_fee_line->discard_changes; |
2303 |
$lost_fee_line->discard_changes; |
2301 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2304 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2302 |
is( $lost_fee_line->accounttype, |
2305 |
is( $lost_fee_line->accounttype, |
2303 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2306 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2307 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2304 |
|
2308 |
|
2305 |
is( $patron->account->balance, |
2309 |
is( $patron->account->balance, |
2306 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
2310 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
Lines 2308-2314
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2308 |
|
2312 |
|
2309 |
subtest 'Test without payment or write off' => sub { |
2313 |
subtest 'Test without payment or write off' => sub { |
2310 |
|
2314 |
|
2311 |
plan tests => 12; |
2315 |
plan tests => 13; |
2312 |
|
2316 |
|
2313 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2317 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2314 |
|
2318 |
|
Lines 2341-2367
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2341 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2345 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2342 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2346 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2343 |
my $lost_fee_line = $lost_fee_lines->next; |
2347 |
my $lost_fee_line = $lost_fee_lines->next; |
2344 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2348 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2345 |
is( $lost_fee_line->amountoutstanding + 0, |
2349 |
is( $lost_fee_line->amountoutstanding + 0, |
2346 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2350 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2347 |
|
2351 |
|
2348 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2352 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2349 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2353 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2350 |
|
2354 |
|
2351 |
is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' ); |
2355 |
is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2352 |
is( $credit_return->amount + 0, -99.00, 'The account line of type CR has an amount of -99' ); |
2356 |
is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2353 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type CR has an amountoutstanding of 0' ); |
2357 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' ); |
2354 |
|
2358 |
|
2355 |
$lost_fee_line->discard_changes; |
2359 |
$lost_fee_line->discard_changes; |
2356 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2360 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2357 |
is( $lost_fee_line->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2361 |
is( $lost_fee_line->accounttype, |
|
|
2362 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2363 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2358 |
|
2364 |
|
2359 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2365 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2360 |
}; |
2366 |
}; |
2361 |
|
2367 |
|
2362 |
subtest 'Test with partial payement and write off, and remaining debt' => sub { |
2368 |
subtest 'Test with partial payement and write off, and remaining debt' => sub { |
2363 |
|
2369 |
|
2364 |
plan tests => 15; |
2370 |
plan tests => 16; |
2365 |
|
2371 |
|
2366 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2372 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2367 |
my $item = $builder->build_sample_item( |
2373 |
my $item = $builder->build_sample_item( |
Lines 2392-2400
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2392 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2398 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2393 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2399 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2394 |
my $lost_fee_line = $lost_fee_lines->next; |
2400 |
my $lost_fee_line = $lost_fee_lines->next; |
2395 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2401 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2396 |
is( $lost_fee_line->amountoutstanding + 0, |
2402 |
is( $lost_fee_line->amountoutstanding + 0, |
2397 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2403 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2398 |
|
2404 |
|
2399 |
my $account = $patron->account; |
2405 |
my $account = $patron->account; |
2400 |
is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' ); |
2406 |
is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' ); |
Lines 2432-2452
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2432 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2438 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2433 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2439 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2434 |
|
2440 |
|
2435 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PF - payment (CR)' ); |
2441 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' ); |
2436 |
|
2442 |
|
2437 |
$lost_fee_line->discard_changes; |
2443 |
$lost_fee_line->discard_changes; |
2438 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2444 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2439 |
is( $lost_fee_line->accounttype, |
2445 |
is( $lost_fee_line->accounttype, |
2440 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2446 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2447 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2441 |
|
2448 |
|
2442 |
is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' ); |
2449 |
is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2443 |
is( $credit_return->amount + 0, |
2450 |
is( $credit_return->amount + 0, |
2444 |
($payment_amount + $outstanding ) * -1, |
2451 |
($payment_amount + $outstanding ) * -1, |
2445 |
'The account line of type CR has an amount equal to the payment + outstanding' |
2452 |
'The account line of type LOST_RETURN has an amount equal to the payment + outstanding' |
2446 |
); |
2453 |
); |
2447 |
is( $credit_return->amountoutstanding + 0, |
2454 |
is( $credit_return->amountoutstanding + 0, |
2448 |
$payment_amount * -1, |
2455 |
$payment_amount * -1, |
2449 |
'The account line of type CR has an amountoutstanding equal to the payment' |
2456 |
'The account line of type LOST_RETURN has an amountoutstanding equal to the payment' |
2450 |
); |
2457 |
); |
2451 |
|
2458 |
|
2452 |
is( $account->balance, |
2459 |
is( $account->balance, |
Lines 2495-2503
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2495 |
{ borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } ); |
2502 |
{ borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } ); |
2496 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2503 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2497 |
my $lost_fee_line = $lost_fee_lines->next; |
2504 |
my $lost_fee_line = $lost_fee_lines->next; |
2498 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2505 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2499 |
is( $lost_fee_line->amountoutstanding + 0, |
2506 |
is( $lost_fee_line->amountoutstanding + 0, |
2500 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2507 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2501 |
|
2508 |
|
2502 |
my $account = $patron->account; |
2509 |
my $account = $patron->account; |
2503 |
is( $account->balance, $replacement_amount, 'Balance is L' ); |
2510 |
is( $account->balance, $replacement_amount, 'Balance is L' ); |
Lines 2527-2533
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2527 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id ); |
2534 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id ); |
2528 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2535 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2529 |
|
2536 |
|
2530 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (CR)' ); |
2537 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' ); |
2531 |
|
2538 |
|
2532 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next; |
2539 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next; |
2533 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
2540 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |