Bug 32891: Fix slot selection in last hour

If the curbside pickup module is configured with slot not on the hour
(minutes=00), the slots in the last (not complete) hour won't be
selectable.

Test plan:
Create the following configuration:
pickup interval: 10
Opening hours: 08:00 to 11:30
Create a pickup and select 11:10 or 11:20
=> Without this patch the pickup is not created and the UI displays "Wrong slot selected"
=> With this patch you are able to create the pickup

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Caroline Cyr La Rose <caroline.cyr-la-rose@inlibro.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-02-07 08:48:29 +01:00 committed by Tomas Cohen Arazi
parent 64e14f90b5
commit f2f288a8c4
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
2 changed files with 14 additions and 7 deletions

View file

@ -103,7 +103,7 @@ sub is_valid_pickup_datetime {
my $start = $datetime->clone->set_hour( $opening_slot->start_hour )
->set_minute( $opening_slot->start_minute );
my $end = $datetime->clone->set_hour( $opening_slot->end_hour )
->set_minute( $opening_slot->start_minute );
->set_minute( $opening_slot->end_minute );
my $keep_going = 1;
my $slot_start = $start->clone;
my $slot_end = $slot_start->clone->add(minutes => $self->pickup_interval);

View file

@ -56,7 +56,7 @@ my $policy = Koha::CurbsidePickupPolicy->new(
branchcode => $library->branchcode,
enabled => 1,
enable_waiting_holds_only => 0,
pickup_interval => 30,
pickup_interval => 15,
patrons_per_interval => 2,
patron_scheduled_pickup => 1
}
@ -73,12 +73,12 @@ my $policy_disabled = Koha::CurbsidePickupPolicy->new(
)->store;
# Open Mondays from 12 to 18
$policy->add_opening_slot('1-12:00-18:00');
$policy->add_opening_slot('1-12:00-18:45');
my $today = dt_from_string;
subtest 'Create a pickup' => sub {
plan tests => 9;
plan tests => 10;
# Day and datetime are ok
my $next_monday =
@ -99,7 +99,9 @@ subtest 'Create a pickup' => sub {
'Koha::Exceptions::CurbsidePickup::NotEnabled',
'Cannot create pickup if the policy does not allow it';
$policy->enable_waiting_holds_only(1)->store;
$policy->enabled(1)->store;
$policy->enable_waiting_holds_only(1)->store;
throws_ok {
Koha::CurbsidePickup->new($params)->store;
}
@ -119,6 +121,11 @@ subtest 'Create a pickup' => sub {
$cp->delete;
$schedule_dt = $next_monday->set_hour(18)->set_minute(15)->set_second(00);
$cp = Koha::CurbsidePickup->new( { %$params, scheduled_pickup_datetime => $schedule_dt } )->store;
ok($cp);
$cp->delete;
# Day is not ok
my $next_tuesday =
$today->clone->add( days => ( 2 - $today->day_of_week ) % 7 );
@ -137,8 +144,8 @@ subtest 'Create a pickup' => sub {
'Koha::Exceptions::CurbsidePickup::NoMatchingSlots',
'Cannot create a pickup on a time without opening slots defined';
# Day ok, datetime inside the opening slot, but wrong (15:15 for instance)
$schedule_dt = $next_monday->set_hour(15)->set_minute(15)->set_second(00);
# Day ok, datetime inside the opening slot, but wrong (15:07 for instance)
$schedule_dt = $next_monday->set_hour(15)->set_minute(07)->set_second(00);
throws_ok {
Koha::CurbsidePickup->new({%$params, scheduled_pickup_datetime => $schedule_dt})->store;
}