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

(-)a/t/db_dependent/Circulation.t (-19 / +23 lines)
Lines 2080-2086 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2080
2080
2081
    subtest 'Full write-off tests' => sub {
2081
    subtest 'Full write-off tests' => sub {
2082
2082
2083
        plan tests => 10;
2083
        plan tests => 11;
2084
2084
2085
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2085
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2086
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
2086
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
Lines 2114-2122 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2114
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2114
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2115
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2115
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2116
        my $lost_fee_line = $lost_fee_lines->next;
2116
        my $lost_fee_line = $lost_fee_lines->next;
2117
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2117
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2118
        is( $lost_fee_line->amountoutstanding + 0,
2118
        is( $lost_fee_line->amountoutstanding + 0,
2119
            $replacement_amount, 'The right L amountoutstanding is generated' );
2119
            $replacement_amount, 'The right LOST amountoutstanding is generated' );
2120
2120
2121
        my $account = $patron->account;
2121
        my $account = $patron->account;
2122
        my $debts   = $account->outstanding_debits;
2122
        my $debts   = $account->outstanding_debits;
Lines 2136-2149 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2136
        $lost_fee_line->discard_changes; # reload from DB
2136
        $lost_fee_line->discard_changes; # reload from DB
2137
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2137
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2138
        is( $lost_fee_line->accounttype,
2138
        is( $lost_fee_line->accounttype,
2139
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2139
            'LOST', 'Lost fee now still has account type of LOST' );
2140
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2140
2141
2141
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2142
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2142
    };
2143
    };
2143
2144
2144
    subtest 'Full payment tests' => sub {
2145
    subtest 'Full payment tests' => sub {
2145
2146
2146
        plan tests => 12;
2147
        plan tests => 13;
2147
2148
2148
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2149
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2149
2150
Lines 2175-2183 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2175
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2176
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2176
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2177
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2177
        my $lost_fee_line = $lost_fee_lines->next;
2178
        my $lost_fee_line = $lost_fee_lines->next;
2178
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2179
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2179
        is( $lost_fee_line->amountoutstanding + 0,
2180
        is( $lost_fee_line->amountoutstanding + 0,
2180
            $replacement_amount, 'The right L amountountstanding is generated' );
2181
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2181
2182
2182
        my $account = $patron->account;
2183
        my $account = $patron->account;
2183
        my $debts   = $account->outstanding_debits;
2184
        my $debts   = $account->outstanding_debits;
Lines 2203-2209 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2203
        $lost_fee_line->discard_changes;
2204
        $lost_fee_line->discard_changes;
2204
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2205
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2205
        is( $lost_fee_line->accounttype,
2206
        is( $lost_fee_line->accounttype,
2206
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2207
            'LOST', 'Lost fee now still has account type of LOST' );
2208
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2207
2209
2208
        is( $patron->account->balance,
2210
        is( $patron->account->balance,
2209
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
2211
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
Lines 2211-2217 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2211
2213
2212
    subtest 'Test without payment or write off' => sub {
2214
    subtest 'Test without payment or write off' => sub {
2213
2215
2214
        plan tests => 12;
2216
        plan tests => 13;
2215
2217
2216
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2218
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2217
2219
Lines 2244-2252 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2244
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2246
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2245
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2247
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2246
        my $lost_fee_line = $lost_fee_lines->next;
2248
        my $lost_fee_line = $lost_fee_lines->next;
2247
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2249
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2248
        is( $lost_fee_line->amountoutstanding + 0,
2250
        is( $lost_fee_line->amountoutstanding + 0,
2249
            $replacement_amount, 'The right L amountountstanding is generated' );
2251
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2250
2252
2251
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2253
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2252
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2254
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
Lines 2257-2270 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2257
2259
2258
        $lost_fee_line->discard_changes;
2260
        $lost_fee_line->discard_changes;
2259
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2261
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2260
        is( $lost_fee_line->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2262
        is( $lost_fee_line->accounttype,
2263
            'LOST', 'Lost fee now still has account type of LOST' );
2264
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2261
2265
2262
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2266
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2263
    };
2267
    };
2264
2268
2265
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2269
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2266
2270
2267
        plan tests => 15;
2271
        plan tests => 16;
2268
2272
2269
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2273
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2270
        my $item = $builder->build_sample_item(
2274
        my $item = $builder->build_sample_item(
Lines 2295-2303 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2295
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2299
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2296
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2300
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2297
        my $lost_fee_line = $lost_fee_lines->next;
2301
        my $lost_fee_line = $lost_fee_lines->next;
2298
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2302
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2299
        is( $lost_fee_line->amountoutstanding + 0,
2303
        is( $lost_fee_line->amountoutstanding + 0,
2300
            $replacement_amount, 'The right L amountountstanding is generated' );
2304
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2301
2305
2302
        my $account = $patron->account;
2306
        my $account = $patron->account;
2303
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
2307
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
Lines 2340-2346 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2340
        $lost_fee_line->discard_changes;
2344
        $lost_fee_line->discard_changes;
2341
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2345
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2342
        is( $lost_fee_line->accounttype,
2346
        is( $lost_fee_line->accounttype,
2343
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2347
            'LOST', 'Lost fee now still has account type of LOST' );
2348
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2344
2349
2345
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2350
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2346
        is( $credit_return->amount + 0,
2351
        is( $credit_return->amount + 0,
Lines 2398-2406 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2398
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2403
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2399
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2404
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2400
        my $lost_fee_line = $lost_fee_lines->next;
2405
        my $lost_fee_line = $lost_fee_lines->next;
2401
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2406
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2402
        is( $lost_fee_line->amountoutstanding + 0,
2407
        is( $lost_fee_line->amountoutstanding + 0,
2403
            $replacement_amount, 'The right L amountountstanding is generated' );
2408
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2404
2409
2405
        my $account = $patron->account;
2410
        my $account = $patron->account;
2406
        is( $account->balance, $replacement_amount, 'Balance is L' );
2411
        is( $account->balance, $replacement_amount, 'Balance is L' );
2407
- 

Return to bug 22563