From: Galen Charlton Date: Thu, 21 May 2020 22:05:31 +0000 (-0400) Subject: various fixes to OpenILS::Application::Curbside X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b34999a3e3015f82eba9cf0c716795a760be72d0;p=working%2FEvergreen.git various fixes to OpenILS::Application::Curbside * fix references to "arrival" column * accept curbside times that lack seconds I.e., open-ils.curbside.create_appointment will now accept both "12:45" and "12:45:00" when setting an appointment * fixes to open-ils.curbside.delete_appointment - correct API doc - fix bug that prevented deletion - make it return a true value upon success * fix uses of flesh_fields * fix crash in open-ils.curbside.fetch_to_be_staged * fix crash in open-ils.curbside.fetch_to_be_staged.latest * fix crash in open-ils.curbside.mark_arrived * fix calculation of slot time: account for TZ; calculate offset correctly * fix crash in open-ils.curbside.mark_delivered Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm index 3ae817b31e..ad682c1848 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm @@ -38,7 +38,7 @@ sub fetch_delivered { # returns appointments delivered TODAY arrival => { '!=' => undef}, delivered => { '>' => 'today'}, },{ - flesh => 1, flesh_fields => {acsp => 'patron'}, + flesh => 1, flesh_fields => {acsp => ['patron']}, order_by => { acsp => {delivered => {direction => 'desc'}} } }]); @@ -109,7 +109,7 @@ sub fetch_arrived { arrival => { '!=' => undef}, delivered => undef, },{ - flesh => 1, flesh_fields => {acsp => 'patron'}, + flesh => 1, flesh_fields => {acsp => ['patron']}, order_by => { acsp => 'arrival' } }]); @@ -160,7 +160,7 @@ sub fetch_latest_arrived { limit => 1, order_by => { acsp => { arrival => { direction => 'desc' } } } }]); - return @$slots ? $$slots[0]->arrived : undef; + return @$slots ? $$slots[0]->arrival : undef; } __PACKAGE__->register_method( method => "fetch_latest_arrived", @@ -189,9 +189,9 @@ sub fetch_staged { my $slots = $e->search_action_curbside([{ org => $org, staged => { '!=' => undef}, - arrived => undef + arrival => undef },{ - flesh => 1, flesh_fields => {acsp => 'patron'}, + flesh => 1, flesh_fields => {acsp => ['patron']}, order_by => { acsp => 'slot' } }]); @@ -237,7 +237,7 @@ sub fetch_latest_staged { my $slots = $e->search_action_curbside([{ org => $org, staged => { '!=' => undef}, - arrived => undef + arrival => undef },{ limit => 1, order_by => { acsp => { slot => { direction => 'desc' } } } }]); @@ -270,7 +270,7 @@ sub fetch_to_be_staged { my $gran = $U->ou_ancestor_setting_value($org, 'circ.curbside.granularity') || '15 minutes'; my $gran_seconds = interval_to_seconds($gran); - my $horizon = new DateTime; + my $horizon = DateTime->now; $horizon->add(seconds => $gran_seconds * 2); my $slots = $e->search_action_curbside([{ @@ -278,7 +278,7 @@ sub fetch_to_be_staged { staged => undef, slot => { '<=' => $horizon->strftime('%FT%T%z') }, },{ - flesh => 1, flesh_fields => {acsp => 'patron'}, + flesh => 1, flesh_fields => {acsp => ['patron']}, order_by => { acsp => 'slot' } }]); @@ -323,7 +323,7 @@ sub fetch_latest_to_be_staged { my $gran = $U->ou_ancestor_setting_value($org, 'circ.curbside.granularity') || '15 minutes'; my $gran_seconds = interval_to_seconds($gran); - my $horizon = new DateTime; + my $horizon = DateTime->now; $horizon->add(seconds => $gran_seconds * 2); my $slots = $e->search_action_curbside([{ @@ -435,15 +435,20 @@ sub create_update_appointment { my $date_obj = $date_parser->parse_datetime($date); return undef unless ($date_obj); + if ($time =~ /^\d\d:\d\d$/) { + $time .= ":00"; # tack on seconds if needed to keep + # interval_to_seconds happy + } + my $slot; # do they already have an open slot? - # NOTE: once arrived is set, it's past the point of editing. + # NOTE: once arrival is set, it's past the point of editing. my $old_slot = $e->search_action_curbside({ - patron => $patron, - org => $org, - slot => { '!=' => undef }, - arrived=> undef + patron => $patron, + org => $org, + slot => { '!=' => undef }, + arrival => undef })->[0]; if ($old_slot) { if ($mode eq 'create') { @@ -481,13 +486,15 @@ sub create_update_appointment { return undef if ($time_seconds < $open_seconds); # too early return undef if ($time_seconds > $close_seconds + 1); # too late (/at/ closing allowed) - $date_obj = $date_parser->parse_datetime($date.'T'.$open_time); + my $tz = $U->ou_ancestor_setting_value($org, 'lib.timezone') || 'local'; + + $date_obj = $date_parser->parse_datetime($date.'T'.$open_time)->set_time_zone($tz); - my $time_into_open_second = $time - $open_time; + my $time_into_open_second = $time_seconds - $open_seconds; if (my $extra_time = $time_into_open_second % $gran) { # a remainder means we got a time we shouldn't have $time_into_open_second -= $extra_time; # just back it off to have staff gather earlier } - + my $slot_ts = $date_obj->add(seconds => $time_into_open_second)->strftime('%FT%T%z'); # finally, confirm that there aren't too many already @@ -501,10 +508,10 @@ sub create_update_appointment { my $method = 'update_action_curbside'; if ($mode eq 'create' or !$slot) { $slot = $e->search_action_curbside({ - patron => $patron, - org => $org, - slot => undef, - arrived=> undef, + patron => $patron, + org => $org, + slot => undef, + arrival => undef, })->[0]; } @@ -574,14 +581,14 @@ sub delete_appointment { my $slot = $e->retrieve_action_curbside($appointment); return undef unless ($slot); - unless ($appointment->patron == $e->requestor->id) { + unless ($slot->patron == $e->requestor->id) { return $e->die_event unless $e->allowed("STAFF_LOGIN"); } $e->delete_action_curbside($slot) or return $e->die_event; $e->commit; - return undef; + return 1; } __PACKAGE__->register_method( method => "delete_appointment", @@ -589,9 +596,7 @@ __PACKAGE__->register_method( signature => { params => [ {type => 'string', desc => 'Authentication token'}, - {type => 'number', desc => 'Patron'}, - {type => 'string', desc => 'Date'}, - {type => 'string', desc => 'Time'}, + {type => 'number', desc => 'Appointment ID'}, ], return => { desc => 'Nothing on success or no appointment found'. 'an ILS Event on permission error'} @@ -635,7 +640,7 @@ sub mark_arrived { my $slot = $e->retrieve_action_curbside($appointment); return undef unless ($slot); - unless ($appointment->patron == $e->requestor->id) { + unless ($slot->patron == $e->requestor->id) { return $e->die_event unless $e->allowed("STAFF_LOGIN"); } @@ -680,7 +685,7 @@ sub mark_delivered { $slot->delivered('now'); $slot->delivery_staff($e->requestor->id); - $slot = $e->update_action_curbside($slot) or return $e->die_event; + $e->update_action_curbside($slot) or return $e->die_event; $e->commit; my $holds = $e->search_action_hold_request({ @@ -703,7 +708,7 @@ sub mark_delivered { $conn->respond($_->gather(1)) for @requests; $circ_sess->disconnect; - return $slot; + return $slot->id; } __PACKAGE__->register_method( method => "mark_delivered",