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

(-)a/t/db_dependent/Circulation.t (-30 / +37 lines)
Lines 2082-2088 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2082
2082
2083
    subtest 'Full write-off tests' => sub {
2083
    subtest 'Full write-off tests' => sub {
2084
2084
2085
        plan tests => 10;
2085
        plan tests => 12;
2086
2086
2087
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2087
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2088
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
2088
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
Lines 2116-2124 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2116
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2116
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2117
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2117
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2118
        my $lost_fee_line = $lost_fee_lines->next;
2118
        my $lost_fee_line = $lost_fee_lines->next;
2119
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2119
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2120
        is( $lost_fee_line->amountoutstanding + 0,
2120
        is( $lost_fee_line->amountoutstanding + 0,
2121
            $replacement_amount, 'The right L amountoutstanding is generated' );
2121
            $replacement_amount, 'The right LOST amountoutstanding is generated' );
2122
        is( $lost_fee_line->status,
2123
            undef, 'The LOST status was not set' );
2122
2124
2123
        my $account = $patron->account;
2125
        my $account = $patron->account;
2124
        my $debts   = $account->outstanding_debits;
2126
        my $debts   = $account->outstanding_debits;
Lines 2133-2151 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2133
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
2135
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
2134
2136
2135
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2137
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2136
        is( $credit_return_id, undef, 'No CR account line added' );
2138
        is( $credit_return_id, undef, 'No LOST_RETURN account line added' );
2137
2139
2138
        $lost_fee_line->discard_changes; # reload from DB
2140
        $lost_fee_line->discard_changes; # reload from DB
2139
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2141
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2140
        is( $lost_fee_line->accounttype,
2142
        is( $lost_fee_line->accounttype,
2141
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2143
            'LOST', 'Lost fee now still has account type of LOST' );
2144
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2142
2145
2143
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2146
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2144
    };
2147
    };
2145
2148
2146
    subtest 'Full payment tests' => sub {
2149
    subtest 'Full payment tests' => sub {
2147
2150
2148
        plan tests => 12;
2151
        plan tests => 13;
2149
2152
2150
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2153
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2151
2154
Lines 2177-2185 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2177
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2180
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2178
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2181
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2179
        my $lost_fee_line = $lost_fee_lines->next;
2182
        my $lost_fee_line = $lost_fee_lines->next;
2180
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2183
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2181
        is( $lost_fee_line->amountoutstanding + 0,
2184
        is( $lost_fee_line->amountoutstanding + 0,
2182
            $replacement_amount, 'The right L amountountstanding is generated' );
2185
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2183
2186
2184
        my $account = $patron->account;
2187
        my $account = $patron->account;
2185
        my $debts   = $account->outstanding_debits;
2188
        my $debts   = $account->outstanding_debits;
Lines 2196-2211 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2196
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2199
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2197
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2200
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2198
2201
2199
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2202
        is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2200
        is( $credit_return->amount + 0,
2203
        is( $credit_return->amount + 0,
2201
            -99.00, 'The account line of type CR has an amount of -99' );
2204
            -99.00, 'The account line of type LOST_RETURN has an amount of -99' );
2202
        is( $credit_return->amountoutstanding + 0,
2205
        is( $credit_return->amountoutstanding + 0,
2203
            -99.00, 'The account line of type CR has an amountoutstanding of -99' );
2206
            -99.00, 'The account line of type LOST_RETURN has an amountoutstanding of -99' );
2204
2207
2205
        $lost_fee_line->discard_changes;
2208
        $lost_fee_line->discard_changes;
2206
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2209
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2207
        is( $lost_fee_line->accounttype,
2210
        is( $lost_fee_line->accounttype,
2208
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2211
            'LOST', 'Lost fee now still has account type of LOST' );
2212
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2209
2213
2210
        is( $patron->account->balance,
2214
        is( $patron->account->balance,
2211
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
2215
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
Lines 2213-2219 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2213
2217
2214
    subtest 'Test without payment or write off' => sub {
2218
    subtest 'Test without payment or write off' => sub {
2215
2219
2216
        plan tests => 12;
2220
        plan tests => 13;
2217
2221
2218
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2222
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2219
2223
Lines 2246-2272 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2246
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2250
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2247
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2251
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2248
        my $lost_fee_line = $lost_fee_lines->next;
2252
        my $lost_fee_line = $lost_fee_lines->next;
2249
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2253
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2250
        is( $lost_fee_line->amountoutstanding + 0,
2254
        is( $lost_fee_line->amountoutstanding + 0,
2251
            $replacement_amount, 'The right L amountountstanding is generated' );
2255
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2252
2256
2253
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2257
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2254
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2258
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2255
2259
2256
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2260
        is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2257
        is( $credit_return->amount + 0, -99.00, 'The account line of type CR has an amount of -99' );
2261
        is( $credit_return->amount + 0, -99.00, 'The account line of type LOST_RETURN has an amount of -99' );
2258
        is( $credit_return->amountoutstanding + 0, 0, 'The account line of type CR has an amountoutstanding of 0' );
2262
        is( $credit_return->amountoutstanding + 0, 0, 'The account line of type LOST_RETURN has an amountoutstanding of 0' );
2259
2263
2260
        $lost_fee_line->discard_changes;
2264
        $lost_fee_line->discard_changes;
2261
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2265
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2262
        is( $lost_fee_line->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2266
        is( $lost_fee_line->accounttype,
2267
            'LOST', 'Lost fee now still has account type of LOST' );
2268
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2263
2269
2264
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2270
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2265
    };
2271
    };
2266
2272
2267
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2273
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2268
2274
2269
        plan tests => 15;
2275
        plan tests => 16;
2270
2276
2271
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2277
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2272
        my $item = $builder->build_sample_item(
2278
        my $item = $builder->build_sample_item(
Lines 2297-2305 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2297
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2303
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2298
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2304
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2299
        my $lost_fee_line = $lost_fee_lines->next;
2305
        my $lost_fee_line = $lost_fee_lines->next;
2300
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2306
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2301
        is( $lost_fee_line->amountoutstanding + 0,
2307
        is( $lost_fee_line->amountoutstanding + 0,
2302
            $replacement_amount, 'The right L amountountstanding is generated' );
2308
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2303
2309
2304
        my $account = $patron->account;
2310
        my $account = $patron->account;
2305
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
2311
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
Lines 2337-2357 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2337
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2343
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2338
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2344
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2339
2345
2340
        is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PF - payment (CR)' );
2346
        is( $account->balance, $processfee_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' );
2341
2347
2342
        $lost_fee_line->discard_changes;
2348
        $lost_fee_line->discard_changes;
2343
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2349
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2344
        is( $lost_fee_line->accounttype,
2350
        is( $lost_fee_line->accounttype,
2345
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2351
            'LOST', 'Lost fee now still has account type of LOST' );
2352
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2346
2353
2347
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2354
        is( $credit_return->accounttype, 'LOST_RETURN', 'An account line of type LOST_RETURN is added' );
2348
        is( $credit_return->amount + 0,
2355
        is( $credit_return->amount + 0,
2349
            ($payment_amount + $outstanding ) * -1,
2356
            ($payment_amount + $outstanding ) * -1,
2350
            'The account line of type CR has an amount equal to the payment + outstanding'
2357
            'The account line of type LOST_RETURN has an amount equal to the payment + outstanding'
2351
        );
2358
        );
2352
        is( $credit_return->amountoutstanding + 0,
2359
        is( $credit_return->amountoutstanding + 0,
2353
            $payment_amount * -1,
2360
            $payment_amount * -1,
2354
            'The account line of type CR has an amountoutstanding equal to the payment'
2361
            'The account line of type LOST_RETURN has an amountoutstanding equal to the payment'
2355
        );
2362
        );
2356
2363
2357
        is( $account->balance,
2364
        is( $account->balance,
Lines 2400-2408 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2400
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2407
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2401
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2408
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2402
        my $lost_fee_line = $lost_fee_lines->next;
2409
        my $lost_fee_line = $lost_fee_lines->next;
2403
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2410
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2404
        is( $lost_fee_line->amountoutstanding + 0,
2411
        is( $lost_fee_line->amountoutstanding + 0,
2405
            $replacement_amount, 'The right L amountountstanding is generated' );
2412
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2406
2413
2407
        my $account = $patron->account;
2414
        my $account = $patron->account;
2408
        is( $account->balance, $replacement_amount, 'Balance is L' );
2415
        is( $account->balance, $replacement_amount, 'Balance is L' );
Lines 2432-2438 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2432
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2439
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2433
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2440
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2434
2441
2435
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (CR)' );
2442
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' );
2436
2443
2437
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next;
2444
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next;
2438
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2445
        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