From ad463f99fd77f80b9731b4d666db27fa26ceadaf 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 Removed the results[0] test too in addbiblio, since there can be warnings without effectively cancelled order lines. Also reworded the warn (cancelled, not deleted). Test plan: Run t/db_dependent/Koha/Acquisition/Orders.t Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer --- Koha/Acquisition/Orders.pm | 1 + cataloguing/addbiblio.pl | 4 ++-- t/db_dependent/Koha/Acquisition/Orders.t | 4 ++-- 3 files changed, 5 insertions(+), 4 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/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 9d5a216549..91303857ec 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -789,8 +789,8 @@ elsif ( $op eq "cud-delete" ) { try { my @result = Koha::Acquisition::Orders->search( { biblionumber => $biblionumber } )->cancel; my $warns = @{ $result[1] }; - if ( $result[0] && $warns ) { # warnings about order lines not removed - warn sprintf( "%d order lines were deleted, but %d lines gave a warning\n", $result[0], $warns ); + if ($warns) { # warnings about order lines not cancelled + warn sprintf( "%d order lines were cancelled, but %d lines gave a warning\n", $result[0], $warns ); } $error = &DelBiblio($biblionumber); } catch { 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.39.5