@@ -, +, @@ --- Koha/Account/Line.pm | 13 +++++++++++-- Koha/REST/V1/Patrons/Account.pm | 5 ++--- 2 files changed, 13 insertions(+), 5 deletions(-) --- a/Koha/Account/Line.pm +++ a/Koha/Account/Line.pm @@ -657,7 +657,14 @@ sub apply { # Attempt to renew the item associated with this debit if # appropriate if ( $self->credit_type_code ne 'FORGIVEN' && $debit->is_renewable ) { - $debit->renew_item( { interface => $params->{interface} } ); + my $outcome = $debit->renew_item( { interface => $params->{interface} } ); + $self->add_message( + { + type => 'info', + message => 'renewal', + payload => $outcome + } + ) if $outcome; } # Same logic exists in Koha::Account::pay @@ -677,10 +684,12 @@ sub apply { C4::Circulation::ReturnLostItem( $self->borrowernumber, $debit->itemnumber ); } + + last if $available_credit == 0; } }); - return $available_credit; + return $self; } =head3 payout --- a/Koha/REST/V1/Patrons/Account.pm +++ a/Koha/REST/V1/Patrons/Account.pm @@ -132,13 +132,12 @@ sub add_credit { $debits = Koha::Account::Lines->search({ accountlines_id => { -in => $debits_ids } }) if $debits_ids; - my $outstanding_credit = $credit->amountoutstanding; if ($debits) { # pay them! - $outstanding_credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' }); + $credit = $credit->apply({ debits => [ $debits->as_list ], offset_type => 'payment' }); } - if ($outstanding_credit) { + if ($credit->amountoutstanding != 0) { my $outstanding_debits = $account->outstanding_debits; $credit->apply({ debits => [ $outstanding_debits->as_list ], offset_type => 'payment' }); } --