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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Marcel de Rooy 2024-04-26 09:19:29 +00:00 committed by Katrin Fischer
parent 362cfb3c47
commit ad463f99fd
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 5 additions and 4 deletions

View File

@ -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 } ) {

View File

@ -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 {

View File

@ -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;
};