From 1af964aabafe43394cff94cb2011272c80e7a777 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 27 Jun 2024 16:55:55 +0100 Subject: [PATCH] Bug 28664: (follow-up) Throw exception if debt if VOID This patch adds an exception when an attempt is made to refund against a VOID debit. Test plan 1) Run the included unit test Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer (cherry picked from commit b18664ec45ffbe761c50b6daca487c3222f8a5e0) Signed-off-by: Lucas Gass (cherry picked from commit 46dc45e60c6d8a080e0d9f045a1c3f1ace464f9d) Signed-off-by: Fridolin Somers --- Koha/Account/Line.pm | 4 ++++ t/db_dependent/Koha/Account/Line.t | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 7496f17677..a0a641ded2 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -497,6 +497,10 @@ sub reduce { Koha::Exceptions::Account::IsNotDebit->throw( error => 'Account line ' . $self->id . 'is a payout' ); } + if ( $self->debit_type_code eq 'VOID' ) { + Koha::Exceptions::Account::IsNotDebit->throw( + error => 'Account line ' . $self->id . 'is void' ); + } # Check for mandatory parameters my @mandatory = ( 'interface', 'reduction_type', 'amount' ); diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index 53e596bc09..426cb021dc 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -1071,7 +1071,7 @@ subtest "payout() tests" => sub { subtest "reduce() tests" => sub { - plan tests => 34; + plan tests => 35; $schema->storage->txn_begin; @@ -1254,6 +1254,29 @@ subtest "reduce() tests" => sub { 'Koha::Exceptions::Account::IsNotDebit', '->reduce() cannot be used on a payout debit'; + # Throw exception if attempting to reduce a voided debt + my $payment = Koha::Account::Line->new( + { + borrowernumber => $borrower->borrowernumber, + amount => -20, + amountoutstanding => -20, + interface => 'commandline', + credit_type_code => 'CREDIT' + } + )->store(); + my $void = $payment->void( + { + interface => 'intranet', + staff_id => $staff->borrowernumber, + branch => $branchcode, + } + ); + throws_ok { + $void->reduce($reduce_params); + } + 'Koha::Exceptions::Account::IsNotDebit', + '->reduce() cannot be used on a void debit'; + $schema->storage->txn_rollback; }; -- 2.39.5