Bug 38175: (QA follow-up) Ensure we handle cancelled in clash detection

We need to ensure we handle the new status tracking cancelled/completed
in our clash detection code too.

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:
Martin Renvoize 2024-10-22 17:09:39 +01:00 committed by Katrin Fischer
parent e8185e14cc
commit 24114187f1
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
5 changed files with 82 additions and 40 deletions

View File

@ -296,24 +296,31 @@ sub check_booking {
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
my $existing_bookings = $self->bookings(
[
start_date => {
'-between' => [
$dtf->format_datetime($start_date),
$dtf->format_datetime($end_date)
]
},
end_date => {
'-between' => [
$dtf->format_datetime($start_date),
$dtf->format_datetime($end_date)
]
},
{
start_date => { '<' => $dtf->format_datetime($start_date) },
end_date => { '>' => $dtf->format_datetime($end_date) }
}
]
{
'-and' => [
{
'-or' => [
start_date => {
'-between' => [
$dtf->format_datetime($start_date),
$dtf->format_datetime($end_date)
]
},
end_date => {
'-between' => [
$dtf->format_datetime($start_date),
$dtf->format_datetime($end_date)
]
},
{
start_date => { '<' => $dtf->format_datetime($start_date) },
end_date => { '>' => $dtf->format_datetime($end_date) }
}
]
},
{ status => { '-not_in' => [ 'cancelled', 'completed' ] } }
]
}
);
my $booked_count =

View File

@ -44,8 +44,8 @@ sub filter_by_active {
my ($self) = @_;
return $self->search(
{
end_date => { '>=' => \'NOW()' },
status => { q{!=} => [ -and => qw(cancelled completed) ] }
end_date => { '>=' => \'NOW()' },
status => { '-not_in' => [ 'cancelled', 'completed' ] }
}
);
}

View File

@ -707,24 +707,31 @@ sub check_booking {
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
my $existing_bookings = $self->bookings(
[
start_date => {
'-between' => [
$dtf->format_datetime($start_date),
$dtf->format_datetime($end_date)
]
},
end_date => {
'-between' => [
$dtf->format_datetime($start_date),
$dtf->format_datetime($end_date)
]
},
{
start_date => { '<' => $dtf->format_datetime($start_date) },
end_date => { '>' => $dtf->format_datetime($end_date) }
}
]
{
'-and' => [
{
'-or' => [
start_date => {
'-between' => [
$dtf->format_datetime($start_date),
$dtf->format_datetime($end_date)
]
},
end_date => {
'-between' => [
$dtf->format_datetime($start_date),
$dtf->format_datetime($end_date)
]
},
{
start_date => { '<' => $dtf->format_datetime($start_date) },
end_date => { '>' => $dtf->format_datetime($end_date) }
}
]
},
{ status => { '-not_in' => [ 'cancelled', 'completed' ] } }
]
}
);
my $bookings_count =

View File

@ -1851,7 +1851,7 @@ sub host_record {
}
subtest 'check_booking tests' => sub {
plan tests => 4;
plan tests => 5;
$schema->storage->txn_begin;
@ -1952,5 +1952,19 @@ subtest 'check_booking tests' => sub {
"Koha::Biblio->check_booking returns true if we pass the booking_id of one of the bookings that we would conflict with"
);
# Cancelled booking
$current_bookings[0]->update( { status => 'cancelled' } );
$can_book = $biblio->check_booking(
{
start_date => dt_from_string(),
end_date => dt_from_string()->add( days => 7 ),
}
);
is(
$can_book,
1,
"Koha::Item->check_booking takes account of cancelled status in bookings check"
);
$schema->storage->txn_rollback;
};

View File

@ -3056,7 +3056,7 @@ subtest 'find_booking' => sub {
};
subtest 'check_booking tests' => sub {
plan tests => 5;
plan tests => 6;
$schema->storage->txn_begin;
@ -3145,6 +3145,20 @@ subtest 'check_booking tests' => sub {
"Koha::Item->check_booking returns true if we pass the booking_id that would conflict"
);
# Cancelled booking
$booking2->update( { status => 'cancelled' } );
$can_book = $item->check_booking(
{
start_date => dt_from_string(),
end_date => dt_from_string()->add( days => 7 ),
}
);
is(
$can_book,
1,
"Koha::Item->check_booking returns true if the conflicting booking is cancelled"
);
$booking2->delete();
# Future booking