From d67c41765e874acb2fb55d761d264c8331696abc Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 14 Feb 2024 16:57:50 +0100 Subject: [PATCH] Bug 36068: Do not overwrite cancellation date in ->cancel Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Koha/Acquisition/Order.t Signed-off-by: Marcel de Rooy --- Koha/Acquisition/Order.pm | 8 ++++---- t/db_dependent/Koha/Acquisition/Order.t | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index e0fea073f1..27887b1c60 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -203,12 +203,12 @@ sub cancel { } } - # Update order status + # Update order status; do not overwrite older cancellation date + $self->datecancellationprinted(dt_from_string) unless $self->datecancellationprinted; $self->set( { - cancellationreason => $reason, - datecancellationprinted => \'NOW()', - orderstatus => 'cancelled', + cancellationreason => $reason, + orderstatus => 'cancelled', } )->store; diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t index 10fdfa4685..f0da354697 100755 --- a/t/db_dependent/Koha/Acquisition/Order.t +++ b/t/db_dependent/Koha/Acquisition/Order.t @@ -659,7 +659,7 @@ subtest 'creator ()' => sub { subtest 'cancel() tests' => sub { - plan tests => 56; + plan tests => 58; $schema->storage->txn_begin; @@ -1017,5 +1017,13 @@ subtest 'cancel() tests' => sub { lives_ok { $order->set($columns)->store; } 'No croak on missing biblionumber when cancelling an order'; throws_ok { $order->orderstatus('new')->store; } qr/Cannot insert order: Mandatory parameter biblionumber is missing/, 'Expected croak'; + # Try to cancel again, not overwriting cancellation date + my $dt = dt_from_string->subtract( days => 1 ); + $order->biblionumber($biblio_id)->datecancellationprinted($dt)->orderstatus('new')->store; + $order->cancel; + $order->discard_changes; + is( $order->orderstatus, 'cancelled', 'Check status after second cancel' ); + is( $order->datecancellationprinted, $dt->ymd, 'Check date after second cancel' ); + $schema->storage->txn_rollback; }; -- 2.30.2