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

(-)a/C4/Circulation.pm (-3 / +2 lines)
Lines 2375-2381 sub _FixOverduesOnReturn { Link Here
2375
                    }
2375
                    }
2376
                );
2376
                );
2377
2377
2378
                $credit->apply({ debits => $accountlines->reset, offset_type => 'Forgiven' });
2378
                $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
2379
2379
2380
                $accountline->status('FORGIVEN');
2380
                $accountline->status('FORGIVEN');
2381
2381
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 673-679 sub reconcile_balance { Link Here
673
            and my $credit = $outstanding_credits->next )
673
            and my $credit = $outstanding_credits->next )
674
    {
674
    {
675
        # there's both outstanding debits and credits
675
        # there's both outstanding debits and credits
676
        $credit->apply( { debits => $outstanding_debits } );    # applying credit, no special offset
676
        $credit->apply( { debits => [ $outstanding_debits->as_list ] } );    # applying credit, no special offset
677
677
678
        $outstanding_debits = $self->outstanding_debits;
678
        $outstanding_debits = $self->outstanding_debits;
679
679
(-)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 2132-2138 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2132
                interface => 'test',
2132
                interface => 'test',
2133
            }
2133
            }
2134
        );
2134
        );
2135
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
2135
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } );
2136
2136
2137
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2137
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2138
        is( $credit_return_id, undef, 'No LOST_RETURN account line added' );
2138
        is( $credit_return_id, undef, 'No LOST_RETURN account line added' );
Lines 2194-2200 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2194
                interface => 'test',
2194
                interface => 'test',
2195
            }
2195
            }
2196
        );
2196
        );
2197
        $credit->apply( { debits => $debts, offset_type => 'Payment' } );
2197
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } );
2198
2198
2199
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2199
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2200
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2200
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
Lines 2319-2325 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2319
            }
2319
            }
2320
        );
2320
        );
2321
2321
2322
        $payment->apply( { debits => $lost_fee_lines->reset, offset_type => 'Payment' } );
2322
        $payment->apply( { debits => [ $lost_fee_line ], offset_type => 'Payment' } );
2323
2323
2324
        # Partially write off fee
2324
        # Partially write off fee
2325
        my $write_off_amount = 25;
2325
        my $write_off_amount = 25;
Lines 2329-2335 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2329
                interface => 'test',
2329
                interface => 'test',
2330
            }
2330
            }
2331
        );
2331
        );
2332
        $write_off->apply( { debits => $lost_fee_lines->reset, offset_type => 'Writeoff' } );
2332
        $write_off->apply( { debits => [ $lost_fee_line ], offset_type => 'Writeoff' } );
2333
2333
2334
        is( $account->balance,
2334
        is( $account->balance,
2335
            $processfee_amount + $replacement_amount - $payment_amount - $write_off_amount,
2335
            $processfee_amount + $replacement_amount - $payment_amount - $write_off_amount,
Lines 2422-2428 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2422
                interface => 'test',
2422
                interface => 'test',
2423
            }
2423
            }
2424
        );
2424
        );
2425
        $payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' });
2425
        $payment->apply({ debits => [ $lost_fee_line ], offset_type => 'Payment' });
2426
2426
2427
        is( $account->balance,
2427
        is( $account->balance,
2428
            $replacement_amount - $payment_amount,
2428
            $replacement_amount - $payment_amount,
(-)a/t/db_dependent/Koha/Account.t (-1 / +1 lines)
Lines 394-400 subtest 'lines() tests' => sub { Link Here
394
394
395
    # Paid Off
395
    # Paid Off
396
    $account->add_credit( { amount => 1, interface => 'commandline' } )
396
    $account->add_credit( { amount => 1, interface => 'commandline' } )
397
        ->apply( { debits => scalar $account->outstanding_debits } );
397
        ->apply( { debits => [ $account->outstanding_debits->as_list ] } );
398
398
399
    my $lines = $account->lines;
399
    my $lines = $account->lines;
400
    is( $lines->_resultset->count, 9, "All accountlines (debits, credits and paid off) were fetched");
400
    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 213-219 subtest 'apply() tests' => sub { Link Here
213
    $debit_1->discard_changes;
213
    $debit_1->discard_changes;
214
214
215
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });
215
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });
216
    my $remaining_credit = $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } );
216
    my $remaining_credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
217
    is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' );
217
    is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' );
218
    $credit->discard_changes;
218
    $credit->discard_changes;
219
    is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' );
219
    is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' );
Lines 229-235 subtest 'apply() tests' => sub { Link Here
229
    is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );
229
    is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );
230
230
231
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
231
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
232
    $remaining_credit = $credit->apply( { debits => $debits } );
232
    $remaining_credit = $credit->apply( { debits => [ $debits->as_list ] } );
233
    is( $remaining_credit, 0, 'No remaining credit left' );
233
    is( $remaining_credit, 0, 'No remaining credit left' );
234
    $credit->discard_changes;
234
    $credit->discard_changes;
235
    is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' );
235
    is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' );
Lines 244-263 subtest 'apply() tests' => sub { Link Here
244
244
245
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });
245
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id });
246
    throws_ok
246
    throws_ok
247
        { $credit->apply({ debits => $debits }); }
247
        { $credit->apply({ debits => [ $debits->as_list ] }); }
248
        'Koha::Exceptions::Account::NoAvailableCredit',
248
        'Koha::Exceptions::Account::NoAvailableCredit',
249
        '->apply() can only be used with outstanding credits';
249
        '->apply() can only be used with outstanding credits';
250
250
251
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
251
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
252
    throws_ok
252
    throws_ok
253
        { $debit_1->apply({ debits => $debits }); }
253
        { $debit_1->apply({ debits => [ $debits->as_list ] }); }
254
        'Koha::Exceptions::Account::IsNotCredit',
254
        'Koha::Exceptions::Account::IsNotCredit',
255
        '->apply() can only be used with credits';
255
        '->apply() can only be used with credits';
256
256
257
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
257
    $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id });
258
    my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' });
258
    my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' });
259
    throws_ok
259
    throws_ok
260
        { $credit_3->apply({ debits => $debits }); }
260
        { $credit_3->apply({ debits => [ $debits->as_list ] }); }
261
        'Koha::Exceptions::Account::IsNotDebit',
261
        'Koha::Exceptions::Account::IsNotDebit',
262
        '->apply() can only be applied to credits';
262
        '->apply() can only be applied to credits';
263
263
Lines 274-280 subtest 'apply() tests' => sub { Link Here
274
274
275
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } });
275
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } });
276
    throws_ok {
276
    throws_ok {
277
        $credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } ); }
277
        $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); }
278
        'Koha::Exceptions::Account::IsNotDebit',
278
        'Koha::Exceptions::Account::IsNotDebit',
279
        '->apply() rolls back if any of the passed lines is not a debit';
279
        '->apply() rolls back if any of the passed lines is not a debit';
280
280
Lines 284-290 subtest 'apply() tests' => sub { Link Here
284
    is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );
284
    is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );
285
285
286
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } });
286
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } });
287
    $remaining_credit = $credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } );
287
    $remaining_credit = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
288
288
289
    is( $debit_1->discard_changes->amountoutstanding * 1,  0, 'No changes to already cancelled debit' );
289
    is( $debit_1->discard_changes->amountoutstanding * 1,  0, 'No changes to already cancelled debit' );
290
    is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );
290
    is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );
Lines 397-403 subtest 'adjust() tests' => sub { Link Here
397
397
398
    # Update fine to partially paid
398
    # Update fine to partially paid
399
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
399
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
400
    $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } );
400
    $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
401
401
402
    $debit_2->discard_changes;
402
    $debit_2->discard_changes;
403
    is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' );
403
    is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' );
404
- 

Return to bug 22837