View | Details | Raw Unified | Return to bug 22563
Collapse All | Expand All

(-)a/t/db_dependent/Circulation.t (-30 / +37 lines)
Lines 2128-2134 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2128
2128
2129
    subtest 'Full write-off tests' => sub {
2129
    subtest 'Full write-off tests' => sub {
2130
2130
2131
        plan tests => 10;
2131
        plan tests => 12;
2132
2132
2133
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2133
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2134
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
2134
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
Lines 2162-2170 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2162
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2162
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2163
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2163
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2164
        my $lost_fee_line = $lost_fee_lines->next;
2164
        my $lost_fee_line = $lost_fee_lines->next;
2165
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2165
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2166
        is( $lost_fee_line->amountoutstanding + 0,
2166
        is( $lost_fee_line->amountoutstanding + 0,
2167
            $replacement_amount, 'The right L amountoutstanding is generated' );
2167
            $replacement_amount, 'The right LOST amountoutstanding is generated' );
2168
        is( $lost_fee_line->status,
2169
            undef, 'The LOST status was not set' );
2168
2170
2169
        my $account = $patron->account;
2171
        my $account = $patron->account;
2170
        my $debts   = $account->outstanding_debits;
2172
        my $debts   = $account->outstanding_debits;
Lines 2179-2197 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2179
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
2181
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
2180
2182
2181
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2183
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2182
        is( $credit_return_id, undef, 'No CR account line added' );
2184
        is( $credit_return_id, undef, 'No LOST_RETURN account line added' );
2183
2185
2184
        $lost_fee_line->discard_changes; # reload from DB
2186
        $lost_fee_line->discard_changes; # reload from DB
2185
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2187
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2186
        is( $lost_fee_line->accounttype,
2188
        is( $lost_fee_line->accounttype,
2187
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2189
            'LOST', 'Lost fee now still has account type of LOST' );
2190
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2188
2191
2189
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2192
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2190
    };
2193
    };
2191
2194
2192
    subtest 'Full payment tests' => sub {
2195
    subtest 'Full payment tests' => sub {
2193
2196
2194
        plan tests => 12;
2197
        plan tests => 13;
2195
2198
2196
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2199
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2197
2200
Lines 2223-2231 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2223
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2226
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2224
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2227
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2225
        my $lost_fee_line = $lost_fee_lines->next;
2228
        my $lost_fee_line = $lost_fee_lines->next;
2226
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2229
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2227
        is( $lost_fee_line->amountoutstanding + 0,
2230
        is( $lost_fee_line->amountoutstanding + 0,
2228
            $replacement_amount, 'The right L amountountstanding is generated' );
2231
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2229
2232
2230
        my $account = $patron->account;
2233
        my $account = $patron->account;
2231
        my $debts   = $account->outstanding_debits;
2234
        my $debts   = $account->outstanding_debits;
Lines 2242-2257 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2242
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2245
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2243
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2246
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2244
2247
2245
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2248
        is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2246
        is( $credit_return->amount + 0,
2249
        is( $credit_return->amount + 0,
2247
            -99.00, 'The account line of type CR has an amount of -99' );
2250
            -99.00, 'The account line of type LOST_RETURN has an amount of -99' );
2248
        is( $credit_return->amountoutstanding + 0,
2251
        is( $credit_return->amountoutstanding + 0,
2249
            -99.00, 'The account line of type CR has an amountoutstanding of -99' );
2252
            -99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' );
2250
2253
2251
        $lost_fee_line->discard_changes;
2254
        $lost_fee_line->discard_changes;
2252
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2255
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2253
        is( $lost_fee_line->accounttype,
2256
        is( $lost_fee_line->accounttype,
2254
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2257
            'LOST', 'Lost fee now still has account type of LOST' );
2258
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2255
2259
2256
        is( $patron->account->balance,
2260
        is( $patron->account->balance,
2257
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
2261
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
Lines 2259-2265 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2259
2263
2260
    subtest 'Test without payment or write off' => sub {
2264
    subtest 'Test without payment or write off' => sub {
2261
2265
2262
        plan tests => 12;
2266
        plan tests => 13;
2263
2267
2264
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2268
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2265
2269
Lines 2292-2318 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2292
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2296
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2293
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2297
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2294
        my $lost_fee_line = $lost_fee_lines->next;
2298
        my $lost_fee_line = $lost_fee_lines->next;
2295
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2299
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2296
        is( $lost_fee_line->amountoutstanding + 0,
2300
        is( $lost_fee_line->amountoutstanding + 0,
2297
            $replacement_amount, 'The right L amountountstanding is generated' );
2301
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2298
2302
2299
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2303
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2300
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2304
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2301
2305
2302
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2306
        is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2303
        is( $credit_return->amount + 0, -99.00, 'The account line of type CR has an amount of -99' );
2307
        is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' );
2304
        is( $credit_return->amountoutstanding + 0, 0, 'The account line of type CR has an amountoutstanding of 0' );
2308
        is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' );
2305
2309
2306
        $lost_fee_line->discard_changes;
2310
        $lost_fee_line->discard_changes;
2307
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2311
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2308
        is( $lost_fee_line->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2312
        is( $lost_fee_line->accounttype,
2313
            'LOST', 'Lost fee now still has account type of LOST' );
2314
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2309
2315
2310
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2316
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2311
    };
2317
    };
2312
2318
2313
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2319
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2314
2320
2315
        plan tests => 15;
2321
        plan tests => 16;
2316
2322
2317
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2323
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2318
        my $item = $builder->build_sample_item(
2324
        my $item = $builder->build_sample_item(
Lines 2343-2351 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2343
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2349
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2344
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2350
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2345
        my $lost_fee_line = $lost_fee_lines->next;
2351
        my $lost_fee_line = $lost_fee_lines->next;
2346
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2352
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2347
        is( $lost_fee_line->amountoutstanding + 0,
2353
        is( $lost_fee_line->amountoutstanding + 0,
2348
            $replacement_amount, 'The right L amountountstanding is generated' );
2354
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2349
2355
2350
        my $account = $patron->account;
2356
        my $account = $patron->account;
2351
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
2357
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
Lines 2383-2403 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2383
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2389
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2384
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2390
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2385
2391
2386
        is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PF - payment (CR)' );
2392
        is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' );
2387
2393
2388
        $lost_fee_line->discard_changes;
2394
        $lost_fee_line->discard_changes;
2389
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2395
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2390
        is( $lost_fee_line->accounttype,
2396
        is( $lost_fee_line->accounttype,
2391
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2397
            'LOST', 'Lost fee now still has account type of LOST' );
2398
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2392
2399
2393
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2400
        is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2394
        is( $credit_return->amount + 0,
2401
        is( $credit_return->amount + 0,
2395
            ($payment_amount + $outstanding ) * -1,
2402
            ($payment_amount + $outstanding ) * -1,
2396
            'The account line of type CR has an amount equal to the payment + outstanding'
2403
            'The account line of type LOST_RETURN has an amount equal to the payment + outstanding'
2397
        );
2404
        );
2398
        is( $credit_return->amountoutstanding + 0,
2405
        is( $credit_return->amountoutstanding + 0,
2399
            $payment_amount * -1,
2406
            $payment_amount * -1,
2400
            'The account line of type CR has an amountoutstanding equal to the payment'
2407
            'The account line of type LOST_RETURN has an amountoutstanding equal to the payment'
2401
        );
2408
        );
2402
2409
2403
        is( $account->balance,
2410
        is( $account->balance,
Lines 2446-2454 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2446
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2453
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2447
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2454
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2448
        my $lost_fee_line = $lost_fee_lines->next;
2455
        my $lost_fee_line = $lost_fee_lines->next;
2449
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2456
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2450
        is( $lost_fee_line->amountoutstanding + 0,
2457
        is( $lost_fee_line->amountoutstanding + 0,
2451
            $replacement_amount, 'The right L amountountstanding is generated' );
2458
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2452
2459
2453
        my $account = $patron->account;
2460
        my $account = $patron->account;
2454
        is( $account->balance, $replacement_amount, 'Balance is L' );
2461
        is( $account->balance, $replacement_amount, 'Balance is L' );
Lines 2478-2484 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2478
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2485
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2479
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2486
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2480
2487
2481
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (CR)' );
2488
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' );
2482
2489
2483
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next;
2490
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next;
2484
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2491
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-2 / +1 lines)
Lines 75-81 is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check Link Here
75
75
76
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->{borrowernumber} })->next();
76
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->{borrowernumber} })->next();
77
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
77
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
78
is( $accountline->accounttype, "L", "Account type is L" );
78
is( $accountline->accounttype, "LOST", "Account type is LOST" );
79
79
80
my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
80
my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
81
is( $offset->type, 'Lost Item', 'Got correct offset type' );
81
is( $offset->type, 'Lost Item', 'Got correct offset type' );
82
- 

Return to bug 22563