From d221f0991d6abefd4288972823a6639d70593cd5 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 26 Apr 2024 09:19:29 +0000 Subject: [PATCH] Bug 27893: (follow-up) Check orderstatus in orders->cancel Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Koha/Acquisition/Orders.t Signed-off-by: Marcel de Rooy --- Koha/Acquisition/Orders.pm | 1 + t/db_dependent/Koha/Acquisition/Orders.t | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Koha/Acquisition/Orders.pm b/Koha/Acquisition/Orders.pm index 69fe134ba6..598790d414 100644 --- a/Koha/Acquisition/Orders.pm +++ b/Koha/Acquisition/Orders.pm @@ -287,6 +287,7 @@ sub cancel { my $count = 0; my @messages; while ( my $order = $self->next ) { + next if $order->orderstatus =~ /complete|cancelled/; _correct_quantity($order); # historical ballast $order->cancel( { delete_biblio => $delete_biblio } ); if ( @{ $order->object_messages } ) { diff --git a/t/db_dependent/Koha/Acquisition/Orders.t b/t/db_dependent/Koha/Acquisition/Orders.t index 0fb2bc4031..997110928a 100755 --- a/t/db_dependent/Koha/Acquisition/Orders.t +++ b/t/db_dependent/Koha/Acquisition/Orders.t @@ -196,11 +196,11 @@ subtest 'filter_by_obsolete and cancel' => sub { $rs = Koha::Acquisition::Orders->filter_by_obsolete->search($limit); is( $rs->count, 3, 'Three obsolete' ); my @results = $rs->cancel; - is( $results[0], 3, 'All should be cancelled' ); + is( $results[0], 2, 'Two should be cancelled, one was cancelled already' ); is( @{ $results[1] }, 0, 'No messages' ); is( $order_1->discard_changes->orderstatus, 'cancelled', 'Check orderstatus of order_1' ); isnt( $order_2->discard_changes->datecancellationprinted, undef, 'Cancellation date of order_2 filled' ); - isnt( $order_3->discard_changes->datecancellationprinted, undef, 'Cancellation date of order_3 filled' ); + is( $order_3->discard_changes->datecancellationprinted, undef, 'order_3 was skipped, so date not touched' ); $schema->storage->txn_rollback; }; -- 2.30.2