Bug 36068: Do not overwrite cancellation date in ->cancel

Test plan:
Run t/db_dependent/Koha/Acquisition/Order.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Marcel de Rooy 2024-02-14 16:57:50 +01:00 committed by Katrin Fischer
parent e50582293b
commit 54211c8487
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 13 additions and 5 deletions

View file

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

View file

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