@@ -, +, @@ --- C4/Circulation.pm | 5 ++--- Koha/Account.pm | 2 +- Koha/REST/V1/Patrons/Account.pm | 4 ++-- t/db_dependent/Circulation.t | 10 +++++----- t/db_dependent/Koha/Account.t | 2 +- t/db_dependent/Koha/Account/Lines.t | 16 ++++++++-------- 6 files changed, 19 insertions(+), 20 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2369,7 +2369,7 @@ sub _FixOverduesOnReturn { } ); - $credit->apply({ debits => $accountlines->reset, offset_type => 'Forgiven' }); + $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); $accountline->status('FORGIVEN'); @@ -2450,8 +2450,7 @@ sub _FixAccountForLostAndReturned { } ); - # TODO: ->apply should just accept the accountline - $credit->apply( { debits => $accountlines->reset } ); + $credit->apply( { debits => [ $accountline ] } ); } # Manually set the accounttype --- a/Koha/Account.pm +++ a/Koha/Account.pm @@ -669,7 +669,7 @@ sub reconcile_balance { and my $credit = $outstanding_credits->next ) { # there's both outstanding debits and credits - $credit->apply( { debits => $outstanding_debits } ); # applying credit, no special offset + $credit->apply( { debits => [ $outstanding_debits->as_list ] } ); # applying credit, no special offset $outstanding_debits = $self->outstanding_debits; --- a/Koha/REST/V1/Patrons/Account.pm +++ a/Koha/REST/V1/Patrons/Account.pm @@ -132,12 +132,12 @@ sub add_credit { my $outstanding_credit = $credit->amountoutstanding; if ($debits) { # pay them! - $outstanding_credit = $credit->apply({ debits => $debits, offset_type => 'payment' }); + $outstanding_credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' }); } if ($outstanding_credit) { my $outstanding_debits = $account->outstanding_debits; - $credit->apply({ debits => $outstanding_debits, offset_type => 'payment' }); + $credit->apply({ debits => [ $outstanding_debits->as_list ], offset_type => 'payment' }); } return $c->render( status => 200, openapi => { account_line_id => $credit->id } ); --- a/t/db_dependent/Circulation.t +++ a/t/db_dependent/Circulation.t @@ -2130,7 +2130,7 @@ subtest '_FixAccountForLostAndReturned' => sub { interface => 'test', } ); - $credit->apply( { debits => $debts, offset_type => 'Writeoff' } ); + $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); is( $credit_return_id, undef, 'No CR account line added' ); @@ -2191,7 +2191,7 @@ subtest '_FixAccountForLostAndReturned' => sub { interface => 'test', } ); - $credit->apply( { debits => $debts, offset_type => 'Payment' } ); + $credit->apply( { debits => [ $debts->as_list ], offset_type => 'Payment' } ); my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); my $credit_return = Koha::Account::Lines->find($credit_return_id); @@ -2313,7 +2313,7 @@ subtest '_FixAccountForLostAndReturned' => sub { } ); - $payment->apply( { debits => $lost_fee_lines->reset, offset_type => 'Payment' } ); + $payment->apply( { debits => [ $lost_fee_line ], offset_type => 'Payment' } ); # Partially write off fee my $write_off_amount = 25; @@ -2323,7 +2323,7 @@ subtest '_FixAccountForLostAndReturned' => sub { interface => 'test', } ); - $write_off->apply( { debits => $lost_fee_lines->reset, offset_type => 'Writeoff' } ); + $write_off->apply( { debits => [ $lost_fee_line ], offset_type => 'Writeoff' } ); is( $account->balance, $processfee_amount + $replacement_amount - $payment_amount - $write_off_amount, @@ -2415,7 +2415,7 @@ subtest '_FixAccountForLostAndReturned' => sub { interface => 'test', } ); - $payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' }); + $payment->apply({ debits => [ $lost_fee_line ], offset_type => 'Payment' }); is( $account->balance, $replacement_amount - $payment_amount, --- a/t/db_dependent/Koha/Account.t +++ a/t/db_dependent/Koha/Account.t @@ -394,7 +394,7 @@ subtest 'lines() tests' => sub { # Paid Off $account->add_credit( { amount => 1, interface => 'commandline' } ) - ->apply( { debits => scalar $account->outstanding_debits } ); + ->apply( { debits => [ $account->outstanding_debits->as_list ] } ); my $lines = $account->lines; is( $lines->_resultset->count, 9, "All accountlines (debits, credits and paid off) were fetched"); --- a/t/db_dependent/Koha/Account/Lines.t +++ a/t/db_dependent/Koha/Account/Lines.t @@ -213,7 +213,7 @@ subtest 'apply() tests' => sub { $debit_1->discard_changes; my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); - my $remaining_credit = $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } ); + my $remaining_credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' ); $credit->discard_changes; is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' ); @@ -229,7 +229,7 @@ subtest 'apply() tests' => sub { is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' ); $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); - $remaining_credit = $credit->apply( { debits => $debits } ); + $remaining_credit = $credit->apply( { debits => [ $debits->as_list ] } ); is( $remaining_credit, 0, 'No remaining credit left' ); $credit->discard_changes; is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' ); @@ -244,20 +244,20 @@ subtest 'apply() tests' => sub { $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); throws_ok - { $credit->apply({ debits => $debits }); } + { $credit->apply({ debits => [ $debits->as_list ] }); } 'Koha::Exceptions::Account::NoAvailableCredit', '->apply() can only be used with outstanding credits'; $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); throws_ok - { $debit_1->apply({ debits => $debits }); } + { $debit_1->apply({ debits => [ $debits->as_list ] }); } 'Koha::Exceptions::Account::IsNotCredit', '->apply() can only be used with credits'; $debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' }); throws_ok - { $credit_3->apply({ debits => $debits }); } + { $credit_3->apply({ debits => [ $debits->as_list ] }); } 'Koha::Exceptions::Account::IsNotDebit', '->apply() can only be applied to credits'; @@ -274,7 +274,7 @@ subtest 'apply() tests' => sub { $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } }); throws_ok { - $credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } ); } + $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); } 'Koha::Exceptions::Account::IsNotDebit', '->apply() rolls back if any of the passed lines is not a debit'; @@ -284,7 +284,7 @@ subtest 'apply() tests' => sub { is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' ); $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); - $remaining_credit = $credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } ); + $remaining_credit = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); is( $debit_1->discard_changes->amountoutstanding * 1, 0, 'No changes to already cancelled debit' ); is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); @@ -397,7 +397,7 @@ subtest 'adjust() tests' => sub { # Update fine to partially paid my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); - $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } ); + $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); $debit_2->discard_changes; is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' ); --