Lines 2087-2093
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2087 |
|
2087 |
|
2088 |
subtest 'Full write-off tests' => sub { |
2088 |
subtest 'Full write-off tests' => sub { |
2089 |
|
2089 |
|
2090 |
plan tests => 10; |
2090 |
plan tests => 12; |
2091 |
|
2091 |
|
2092 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2092 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2093 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
2093 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
Lines 2121-2129
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2121 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2121 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2122 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2122 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2123 |
my $lost_fee_line = $lost_fee_lines->next; |
2123 |
my $lost_fee_line = $lost_fee_lines->next; |
2124 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2124 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2125 |
is( $lost_fee_line->amountoutstanding + 0, |
2125 |
is( $lost_fee_line->amountoutstanding + 0, |
2126 |
$replacement_amount, 'The right L amountoutstanding is generated' ); |
2126 |
$replacement_amount, 'The right LOST amountoutstanding is generated' ); |
|
|
2127 |
is( $lost_fee_line->status, |
2128 |
undef, 'The LOST status was not set' ); |
2127 |
|
2129 |
|
2128 |
my $account = $patron->account; |
2130 |
my $account = $patron->account; |
2129 |
my $debts = $account->outstanding_debits; |
2131 |
my $debts = $account->outstanding_debits; |
Lines 2138-2156
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2138 |
$credit->apply( { debits => $debts, offset_type => 'Writeoff' } ); |
2140 |
$credit->apply( { debits => $debts, offset_type => 'Writeoff' } ); |
2139 |
|
2141 |
|
2140 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2142 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2141 |
is( $credit_return_id, undef, 'No CR account line added' ); |
2143 |
is( $credit_return_id, undef, 'No LOST_RETURN account line added' ); |
2142 |
|
2144 |
|
2143 |
$lost_fee_line->discard_changes; # reload from DB |
2145 |
$lost_fee_line->discard_changes; # reload from DB |
2144 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2146 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2145 |
is( $lost_fee_line->accounttype, |
2147 |
is( $lost_fee_line->accounttype, |
2146 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2148 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2149 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2147 |
|
2150 |
|
2148 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2151 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2149 |
}; |
2152 |
}; |
2150 |
|
2153 |
|
2151 |
subtest 'Full payment tests' => sub { |
2154 |
subtest 'Full payment tests' => sub { |
2152 |
|
2155 |
|
2153 |
plan tests => 12; |
2156 |
plan tests => 13; |
2154 |
|
2157 |
|
2155 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2158 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2156 |
|
2159 |
|
Lines 2182-2190
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2182 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2185 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2183 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2186 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2184 |
my $lost_fee_line = $lost_fee_lines->next; |
2187 |
my $lost_fee_line = $lost_fee_lines->next; |
2185 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2188 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2186 |
is( $lost_fee_line->amountoutstanding + 0, |
2189 |
is( $lost_fee_line->amountoutstanding + 0, |
2187 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2190 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2188 |
|
2191 |
|
2189 |
my $account = $patron->account; |
2192 |
my $account = $patron->account; |
2190 |
my $debts = $account->outstanding_debits; |
2193 |
my $debts = $account->outstanding_debits; |
Lines 2201-2216
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2201 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2204 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2202 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2205 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2203 |
|
2206 |
|
2204 |
is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' ); |
2207 |
is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2205 |
is( $credit_return->amount + 0, |
2208 |
is( $credit_return->amount + 0, |
2206 |
-99.00, 'The account line of type CR has an amount of -99' ); |
2209 |
-99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2207 |
is( $credit_return->amountoutstanding + 0, |
2210 |
is( $credit_return->amountoutstanding + 0, |
2208 |
-99.00, 'The account line of type CR has an amountoutstanding of -99' ); |
2211 |
-99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' ); |
2209 |
|
2212 |
|
2210 |
$lost_fee_line->discard_changes; |
2213 |
$lost_fee_line->discard_changes; |
2211 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2214 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2212 |
is( $lost_fee_line->accounttype, |
2215 |
is( $lost_fee_line->accounttype, |
2213 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2216 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2217 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2214 |
|
2218 |
|
2215 |
is( $patron->account->balance, |
2219 |
is( $patron->account->balance, |
2216 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
2220 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
Lines 2218-2224
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2218 |
|
2222 |
|
2219 |
subtest 'Test without payment or write off' => sub { |
2223 |
subtest 'Test without payment or write off' => sub { |
2220 |
|
2224 |
|
2221 |
plan tests => 12; |
2225 |
plan tests => 13; |
2222 |
|
2226 |
|
2223 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2227 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2224 |
|
2228 |
|
Lines 2251-2277
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2251 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2255 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2252 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2256 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2253 |
my $lost_fee_line = $lost_fee_lines->next; |
2257 |
my $lost_fee_line = $lost_fee_lines->next; |
2254 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2258 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2255 |
is( $lost_fee_line->amountoutstanding + 0, |
2259 |
is( $lost_fee_line->amountoutstanding + 0, |
2256 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2260 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2257 |
|
2261 |
|
2258 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2262 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2259 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2263 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2260 |
|
2264 |
|
2261 |
is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' ); |
2265 |
is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2262 |
is( $credit_return->amount + 0, -99.00, 'The account line of type CR has an amount of -99' ); |
2266 |
is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' ); |
2263 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type CR has an amountoutstanding of 0' ); |
2267 |
is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' ); |
2264 |
|
2268 |
|
2265 |
$lost_fee_line->discard_changes; |
2269 |
$lost_fee_line->discard_changes; |
2266 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2270 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2267 |
is( $lost_fee_line->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2271 |
is( $lost_fee_line->accounttype, |
|
|
2272 |
'LOST', 'Lost fee now still has account type of LOST' ); |
2273 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2268 |
|
2274 |
|
2269 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2275 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2270 |
}; |
2276 |
}; |
2271 |
|
2277 |
|
2272 |
subtest 'Test with partial payement and write off, and remaining debt' => sub { |
2278 |
subtest 'Test with partial payement and write off, and remaining debt' => sub { |
2273 |
|
2279 |
|
2274 |
plan tests => 15; |
2280 |
plan tests => 16; |
2275 |
|
2281 |
|
2276 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2282 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2277 |
my $item = $builder->build_sample_item( |
2283 |
my $item = $builder->build_sample_item( |
Lines 2302-2310
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2302 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2308 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2303 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2309 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2304 |
my $lost_fee_line = $lost_fee_lines->next; |
2310 |
my $lost_fee_line = $lost_fee_lines->next; |
2305 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2311 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2306 |
is( $lost_fee_line->amountoutstanding + 0, |
2312 |
is( $lost_fee_line->amountoutstanding + 0, |
2307 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2313 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2308 |
|
2314 |
|
2309 |
my $account = $patron->account; |
2315 |
my $account = $patron->account; |
2310 |
is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' ); |
2316 |
is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' ); |
Lines 2342-2362
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2342 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2348 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2343 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2349 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2344 |
|
2350 |
|
2345 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PF - payment (CR)' ); |
2351 |
is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' ); |
2346 |
|
2352 |
|
2347 |
$lost_fee_line->discard_changes; |
2353 |
$lost_fee_line->discard_changes; |
2348 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2354 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2349 |
is( $lost_fee_line->accounttype, |
2355 |
is( $lost_fee_line->accounttype, |
2350 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2356 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2357 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
2351 |
|
2358 |
|
2352 |
is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' ); |
2359 |
is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' ); |
2353 |
is( $credit_return->amount + 0, |
2360 |
is( $credit_return->amount + 0, |
2354 |
($payment_amount + $outstanding ) * -1, |
2361 |
($payment_amount + $outstanding ) * -1, |
2355 |
'The account line of type CR has an amount equal to the payment + outstanding' |
2362 |
'The account line of type LOST_RETURN has an amount equal to the payment + outstanding' |
2356 |
); |
2363 |
); |
2357 |
is( $credit_return->amountoutstanding + 0, |
2364 |
is( $credit_return->amountoutstanding + 0, |
2358 |
$payment_amount * -1, |
2365 |
$payment_amount * -1, |
2359 |
'The account line of type CR has an amountoutstanding equal to the payment' |
2366 |
'The account line of type LOST_RETURN has an amountoutstanding equal to the payment' |
2360 |
); |
2367 |
); |
2361 |
|
2368 |
|
2362 |
is( $account->balance, |
2369 |
is( $account->balance, |
Lines 2405-2413
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2405 |
{ borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } ); |
2412 |
{ borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } ); |
2406 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2413 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2407 |
my $lost_fee_line = $lost_fee_lines->next; |
2414 |
my $lost_fee_line = $lost_fee_lines->next; |
2408 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2415 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
2409 |
is( $lost_fee_line->amountoutstanding + 0, |
2416 |
is( $lost_fee_line->amountoutstanding + 0, |
2410 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2417 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
2411 |
|
2418 |
|
2412 |
my $account = $patron->account; |
2419 |
my $account = $patron->account; |
2413 |
is( $account->balance, $replacement_amount, 'Balance is L' ); |
2420 |
is( $account->balance, $replacement_amount, 'Balance is L' ); |
Lines 2437-2443
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
2437 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id ); |
2444 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id ); |
2438 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2445 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2439 |
|
2446 |
|
2440 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (CR)' ); |
2447 |
is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' ); |
2441 |
|
2448 |
|
2442 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next; |
2449 |
my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next; |
2443 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |
2450 |
is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); |