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

(-)a/C4/Circulation.pm (-3 / +2 lines)
Lines 2369-2375 sub _FixOverduesOnReturn { Link Here
2369
                    }
2369
                    }
2370
                );
2370
                );
2371
2371
2372
                $credit->apply({ debits => $accountlines->reset, offset_type => 'Forgiven' });
2372
                $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' });
2373
2373
2374
                $accountline->status('FORGIVEN');
2374
                $accountline->status('FORGIVEN');
2375
2375
Lines 2450-2457 sub _FixAccountForLostAndReturned { Link Here
2450
            }
2450
            }
2451
        );
2451
        );
2452
2452
2453
        # TODO: ->apply should just accept the accountline
2453
        $credit->apply( { debits => [ $accountline ] } );
2454
        $credit->apply( { debits => $accountlines->reset } );
2455
    }
2454
    }
2456
2455
2457
    # Manually set the accounttype
2456
    # Manually set the accounttype
(-)a/Koha/Account.pm (-1 / +1 lines)
Lines 669-675 sub reconcile_balance { Link Here
669
            and my $credit = $outstanding_credits->next )
669
            and my $credit = $outstanding_credits->next )
670
    {
670
    {
671
        # there's both outstanding debits and credits
671
        # there's both outstanding debits and credits
672
        $credit->apply( { debits => $outstanding_debits } );    # applying credit, no special offset
672
        $credit->apply( { debits => [ $outstanding_debits->as_list ] } );    # applying credit, no special offset
673
673
674
        $outstanding_debits = $self->outstanding_debits;
674
        $outstanding_debits = $self->outstanding_debits;
675
675
(-)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 2130-2136 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2130
                interface => 'test',
2130
                interface => 'test',
2131
            }
2131
            }
2132
        );
2132
        );
2133
        $credit->apply( { debits => $debts, offset_type => 'Writeoff' } );
2133
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } );
2134
2134
2135
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2135
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2136
        is( $credit_return_id, undef, 'No CR account line added' );
2136
        is( $credit_return_id, undef, 'No CR account line added' );
Lines 2191-2197 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2191
                interface => 'test',
2191
                interface => 'test',
2192
            }
2192
            }
2193
        );
2193
        );
2194
        $credit->apply( { debits => $debts, offset_type => 'Payment' } );
2194
        $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } );
2195
2195
2196
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2196
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2197
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2197
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
Lines 2313-2319 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2313
            }
2313
            }
2314
        );
2314
        );
2315
2315
2316
        $payment->apply( { debits => $lost_fee_lines->reset, offset_type => 'Payment' } );
2316
        $payment->apply( { debits => [ $lost_fee_line ], offset_type => 'Payment' } );
2317
2317
2318
        # Partially write off fee
2318
        # Partially write off fee
2319
        my $write_off_amount = 25;
2319
        my $write_off_amount = 25;
Lines 2323-2329 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2323
                interface => 'test',
2323
                interface => 'test',
2324
            }
2324
            }
2325
        );
2325
        );
2326
        $write_off->apply( { debits => $lost_fee_lines->reset, offset_type => 'Writeoff' } );
2326
        $write_off->apply( { debits => [ $lost_fee_line ], offset_type => 'Writeoff' } );
2327
2327
2328
        is( $account->balance,
2328
        is( $account->balance,
2329
            $processfee_amount + $replacement_amount - $payment_amount - $write_off_amount,
2329
            $processfee_amount + $replacement_amount - $payment_amount - $write_off_amount,
Lines 2415-2421 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2415
                interface => 'test',
2415
                interface => 'test',
2416
            }
2416
            }
2417
        );
2417
        );
2418
        $payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' });
2418
        $payment->apply({ debits => [ $lost_fee_line ], offset_type => 'Payment' });
2419
2419
2420
        is( $account->balance,
2420
        is( $account->balance,
2421
            $replacement_amount - $payment_amount,
2421
            $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