@@ -, +, @@ --- Koha/Account/Line.pm | 4 ++-- .../prog/en/modules/members/boraccount.tt | 12 ++++++++---- members/boraccount.pl | 6 ++++-- t/db_dependent/Accounts.t | 13 +++++++++++-- 4 files changed, 25 insertions(+), 10 deletions(-) --- a/Koha/Account/Line.pm +++ a/Koha/Account/Line.pm @@ -60,11 +60,11 @@ sub void { my ($self) = @_; # Make sure it is a payment we are voiding - return unless $self->accounttype =~ /^Pay/; + return unless $self->amount < 0; my @account_offsets = Koha::Account::Offsets->search( - { credit_id => $self->id, type => 'Payment' } ); + { credit_id => $self->id, amount => { '<' => 0 } } ); $self->_result->result_source->schema->txn_do( sub { --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt @@ -72,10 +72,14 @@ [% END %] Details [% IF ( reverse_col) %] - [% IF ( account.payment ) %] - Reverse - Void - [% ELSE %][% SET footerjs = 1 %] + [% IF ( account.payment || account.amount < 0 ) %] + [% IF account.payment %] + Reverse + [% END %] + [% IF account.amount < 0 %] + Void + [% END %] + [% ELSE %]   [% END %] [% END %] --- a/members/boraccount.pl +++ a/members/boraccount.pl @@ -104,8 +104,10 @@ while ( my $line = $accts->next ) { $accountline->{amount} = sprintf '%.2f', $accountline->{amount}; $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding}; - if ($accountline->{accounttype} =~ /^Pay/) { - $accountline->{payment} = 1; + if ($accountline->{amount} < 0) { + $accountline->{payment} = 1 + if ( $accountline->{accounttype} =~ /^Pay/ ); + $reverse_col = 1; } --- a/t/db_dependent/Accounts.t +++ a/t/db_dependent/Accounts.t @@ -846,7 +846,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub { subtest "Koha::Account::Line::void tests" => sub { - plan tests => 12; + plan tests => 15; # Create a borrower my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; @@ -886,8 +886,9 @@ subtest "Koha::Account::Line::void tests" => sub { is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' ); is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' ); - $account_payment->void(); + my $ret = $account_payment->void(); + is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' ); is( $account->balance(), 30, "Account balance is again 30" ); $account_payment->_result->discard_changes(); @@ -900,6 +901,14 @@ subtest "Koha::Account::Line::void tests" => sub { is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' ); is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' ); + + # Accountlines that are not credits should be un-voidable + my $line1_pre = $line1->unblessed(); + $ret = $line1->void(); + $line1->_result->discard_changes(); + my $line1_post = $line1->unblessed(); + is( $ret, undef, 'Attempted void on non-credit returns undef' ); + is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' ) }; subtest "Koha::Account::Offset credit & debit tests" => sub { --