From 759c23df7d2c0de1d50d13c33606f7a746d9625b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 7 Feb 2023 08:48:29 +0100 Subject: [PATCH] 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 Signed-off-by: Caroline Cyr La Rose Signed-off-by: Tomas Cohen Arazi (cherry picked from commit f2f288a8c409ae32fb15e764bfd980d022315ff8) Signed-off-by: Jacob O'Mara --- Koha/CurbsidePickupPolicy.pm | 2 +- t/db_dependent/Koha/CurbsidePickups.t | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Koha/CurbsidePickupPolicy.pm b/Koha/CurbsidePickupPolicy.pm index 07e0719d17..8408b5f0c2 100644 --- a/Koha/CurbsidePickupPolicy.pm +++ b/Koha/CurbsidePickupPolicy.pm @@ -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); diff --git a/t/db_dependent/Koha/CurbsidePickups.t b/t/db_dependent/Koha/CurbsidePickups.t index ead077ffe0..908d563e82 100755 --- a/t/db_dependent/Koha/CurbsidePickups.t +++ b/t/db_dependent/Koha/CurbsidePickups.t @@ -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; } -- 2.39.5