From 74bcef3b58a11cd4d9aa9e2a8ca5fabc0a876850 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 3 May 2019 13:13:07 +0100 Subject: [PATCH] Bug 22837: Update callers to use new signature --- 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(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 07c1100f33..7b6ad89056 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2375,7 +2375,7 @@ sub _FixOverduesOnReturn { } ); - $credit->apply({ debits => $accountlines->reset, offset_type => 'Forgiven' }); + $credit->apply({ debits => [ $accountline ], offset_type => 'Forgiven' }); $accountline->status('FORGIVEN'); @@ -2459,8 +2459,7 @@ sub _FixAccountForLostAndReturned { } ); - # TODO: ->apply should just accept the accountline - $credit->apply( { debits => $accountlines->reset } ); + $credit->apply( { debits => [ $accountline ] } ); } # Update the account status diff --git a/Koha/Account.pm b/Koha/Account.pm index bcb91709c3..e21c2b97a0 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -673,7 +673,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; diff --git a/Koha/REST/V1/Patrons/Account.pm b/Koha/REST/V1/Patrons/Account.pm index d35e896c93..6dc1912025 100644 --- a/Koha/REST/V1/Patrons/Account.pm +++ b/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 } ); diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index d5d7f0cbc6..dd6142465e 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -2132,7 +2132,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 LOST_RETURN account line added' ); @@ -2194,7 +2194,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); @@ -2319,7 +2319,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; @@ -2329,7 +2329,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, @@ -2422,7 +2422,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, diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index d295b340a2..4aa1e6453d 100755 --- a/t/db_dependent/Koha/Account.t +++ b/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_debit->as_list } ); my $lines = $account->lines; is( $lines->_resultset->count, 9, "All accountlines (debits, credits and paid off) were fetched"); diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index 3856f6ef14..d5a71ef802 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/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' ); -- 2.20.1