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

(-)a/C4/Circulation.pm (-3 / +2 lines)
Lines 2370-2376 sub _FixOverduesOnReturn { Link Here
2370
                    }
2370
                    }
2371
                );
2371
                );
2372
2372
2373
                $credit->apply({ debits => $accountlines->reset, offset_type => 'Forgiven' });
2373
                $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
2374
2374
2375
                $accountline->status('FORGIVEN');
2375
                $accountline->status('FORGIVEN');
2376
2376
Lines 2459-2466 sub _FixAccountForLostAndReturned { Link Here
2459
            }
2459
            }
2460
        );
2460
        );
2461
2461
2462
        # TODO: ->apply should just accept the accountline
2462
        $credit->apply( { debits => [ $accountline ] } );
2463
        $credit->apply( { debits => $accountlines->reset } );
2464
    }
2463
    }
2465
2464
2466
    # Update the account status
2465
    # Update the account status
(-)a/Koha/Account.pm (-1 / +1 lines)
Lines 677-683 sub reconcile_balance { Link Here
677
            and my $credit = $outstanding_credits->next )
677
            and my $credit = $outstanding_credits->next )
678
    {
678
    {
679
        # there's both outstanding debits and credits
679
        # there's both outstanding debits and credits
680
        $credit->apply( { debits => $outstanding_debits } );    # applying credit, no special offset
680
        $credit->apply( { debits => [ $outstanding_debits->as_list ] } );    # applying credit, no special offset
681
681
682
        $outstanding_debits = $self->outstanding_debits;
682
        $outstanding_debits = $self->outstanding_debits;
683
683
(-)a/Koha/REST/V1/Patrons/Account.pm (-2 / +2 lines)
Lines 132-143 sub add_credit { Link Here
132
        my $outstanding_credit = $credit->amountoutstanding;
132
        my $outstanding_credit = $credit->amountoutstanding;
133
        if ($debits) {
133
        if ($debits) {
134
            # pay them!
134
            # pay them!
135
            $outstanding_credit = $credit->apply({ debits => $debits, offset_type => 'payment' });
135
            $outstanding_credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' });
136
        }
136
        }
137
137
138
        if ($outstanding_credit) {
138
        if ($outstanding_credit) {
139
            my $outstanding_debits = $account->outstanding_debits;
139
            my $outstanding_debits = $account->outstanding_debits;
140
            $credit->apply({ debits => $outstanding_debits, offset_type => 'payment' });
140
            $credit->apply({ debits => [ $outstanding_debits->as_list ], offset_type => 'payment' });
141
        }
141
        }
142
142
143
        return $c->render( status => 200, openapi => { account_line_id => $credit->id } );
143
        return $c->render( status => 200, openapi => { account_line_id => $credit->id } );
(-)a/t/db_dependent/Circulation.t (-5 / +5 lines)
Lines 2227-2233 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2227
                interface => 'test',
2227
                interface => 'test',
2228
            }
2228
            }
2229
        );
2229
        );
2230
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
2230
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } );
2231
2231
2232
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2232
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2233
        is( $credit_return_id, undef, 'No LOST_RETURN account line added' );
2233
        is( $credit_return_id, undef, 'No LOST_RETURN account line added' );
Lines 2289-2295 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2289
                interface => 'test',
2289
                interface => 'test',
2290
            }
2290
            }
2291
        );
2291
        );
2292
        $credit->apply( { debits => $debts, offset_type => 'Payment' } );
2292
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } );
2293
2293
2294
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2294
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2295
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2295
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
Lines 2414-2420 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2414
            }
2414
            }
2415
        );
2415
        );
2416
2416
2417
        $payment->apply( { debits => $lost_fee_lines->reset, offset_type => 'Payment' } );
2417
        $payment->apply( { debits => [ $lost_fee_line ], offset_type => 'Payment' } );
2418
2418
2419
        # Partially write off fee
2419
        # Partially write off fee
2420
        my $write_off_amount = 25;
2420
        my $write_off_amount = 25;
Lines 2424-2430 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2424
                interface => 'test',
2424
                interface => 'test',
2425
            }
2425
            }
2426
        );
2426
        );
2427
        $write_off->apply( { debits => $lost_fee_lines->reset, offset_type => 'Writeoff' } );
2427
        $write_off->apply( { debits => [ $lost_fee_line ], offset_type => 'Writeoff' } );
2428
2428
2429
        is( $account->balance,
2429
        is( $account->balance,
2430
            $processfee_amount + $replacement_amount - $payment_amount - $write_off_amount,
2430
            $processfee_amount + $replacement_amount - $payment_amount - $write_off_amount,
Lines 2517-2523 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2517
                interface => 'test',
2517
                interface => 'test',
2518
            }
2518
            }
2519
        );
2519
        );
2520
        $payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' });
2520
        $payment->apply({ debits => [ $lost_fee_line ], offset_type => 'Payment' });
2521
2521
2522
        is( $account->balance,
2522
        is( $account->balance,
2523
            $replacement_amount - $payment_amount,
2523
            $replacement_amount - $payment_amount,
(-)a/t/db_dependent/Koha/Account.t (-1 / +1 lines)
Lines 391-397 subtest 'lines() tests' => sub { Link Here
391
391
392
    # Paid Off
392
    # Paid Off
393
    $account->add_credit( { amount => 1, interface => 'commandline' } )
393
    $account->add_credit( { amount => 1, interface => 'commandline' } )
394
        ->apply( { debits => scalar $account->outstanding_debits } );
394
        ->apply( { debits => [ $account->outstanding_debits->as_list ] } );
395
395
396
    my $lines = $account->lines;
396
    my $lines = $account->lines;
397
    is( $lines->_resultset->count, 9, "All accountlines (debits, credits and paid off) were fetched");
397
    is( $lines->_resultset->count, 9, "All accountlines (debits, credits and paid off) were fetched");
(-)a/t/db_dependent/Koha/Account/Lines.t (-9 / +8 lines)
Lines 242-248 subtest 'apply() tests' => sub { Link Here
242
    $debit_1->discard_changes;
242
    $debit_1->discard_changes;
243
243
244
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });
244
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });
245
    my $remaining_credit = $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } );
245
    my $remaining_credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
246
    is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' );
246
    is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' );
247
    $credit->discard_changes;
247
    $credit->discard_changes;
248
    is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' );
248
    is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' );
Lines 258-264 subtest 'apply() tests' => sub { Link Here
258
    is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );
258
    is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );
259
259
260
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
260
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
261
    $remaining_credit = $credit->apply( { debits => $debits } );
261
    $remaining_credit = $credit->apply( { debits => [ $debits->as_list ] } );
262
    is( $remaining_credit, 0, 'No remaining credit left' );
262
    is( $remaining_credit, 0, 'No remaining credit left' );
263
    $credit->discard_changes;
263
    $credit->discard_changes;
264
    is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' );
264
    is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' );
Lines 273-292 subtest 'apply() tests' => sub { Link Here
273
273
274
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });
274
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });
275
    throws_ok
275
    throws_ok
276
        { $credit->apply({ debits => $debits }); }
276
        { $credit->apply({ debits => [ $debits->as_list ] }); }
277
        'Koha::Exceptions::Account::NoAvailableCredit',
277
        'Koha::Exceptions::Account::NoAvailableCredit',
278
        '->apply() can only be used with outstanding credits';
278
        '->apply() can only be used with outstanding credits';
279
279
280
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
280
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
281
    throws_ok
281
    throws_ok
282
        { $debit_1->apply({ debits => $debits }); }
282
        { $debit_1->apply({ debits => [ $debits->as_list ] }); }
283
        'Koha::Exceptions::Account::IsNotCredit',
283
        'Koha::Exceptions::Account::IsNotCredit',
284
        '->apply() can only be used with credits';
284
        '->apply() can only be used with credits';
285
285
286
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
286
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
287
    my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' });
287
    my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' });
288
    throws_ok
288
    throws_ok
289
        { $credit_3->apply({ debits => $debits }); }
289
        { $credit_3->apply({ debits => [ $debits->as_list ] }); }
290
        'Koha::Exceptions::Account::IsNotDebit',
290
        'Koha::Exceptions::Account::IsNotDebit',
291
        '->apply() can only be applied to credits';
291
        '->apply() can only be applied to credits';
292
292
Lines 303-309 subtest 'apply() tests' => sub { Link Here
303
303
304
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } });
304
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } });
305
    throws_ok {
305
    throws_ok {
306
        $credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } ); }
306
        $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); }
307
        'Koha::Exceptions::Account::IsNotDebit',
307
        'Koha::Exceptions::Account::IsNotDebit',
308
        '->apply() rolls back if any of the passed lines is not a debit';
308
        '->apply() rolls back if any of the passed lines is not a debit';
309
309
Lines 313-319 subtest 'apply() tests' => sub { Link Here
313
    is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );
313
    is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );
314
314
315
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } });
315
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } });
316
    $remaining_credit = $credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } );
316
    $remaining_credit = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
317
317
318
    is( $debit_1->discard_changes->amountoutstanding * 1,  0, 'No changes to already cancelled debit' );
318
    is( $debit_1->discard_changes->amountoutstanding * 1,  0, 'No changes to already cancelled debit' );
319
    is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );
319
    is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );
Lines 426-432 subtest 'adjust() tests' => sub { Link Here
426
426
427
    # Update fine to partially paid
427
    # Update fine to partially paid
428
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
428
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
429
    $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } );
429
    $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
430
430
431
    $debit_2->discard_changes;
431
    $debit_2->discard_changes;
432
    is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' );
432
    is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' );
433
- 

Return to bug 22837