From 71e0e98cc074c6875bd51cefd79e441e9fa0313c Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Mon, 15 Jun 2020 11:41:11 -0400 Subject: [PATCH] LP#1879983: make fetch_{staged,arrived,delivered} return holds This allows the corresponding tabs in the staff user interface to display the list of items, allowing for better error-checking by staff. In the case of fetch_delivered, a heuristic is used: holds that have been marked fulfilled at the appointment's pickup library within 90 seconds of the appointment's delivered timestamp are included. Signed-off-by: Galen Charlton --- .../perlmods/lib/OpenILS/Application/Curbside.pm | 89 +++++++++++----------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm index 6a9df9b4c3..d3b76fdbde 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Curbside.pm @@ -143,6 +143,44 @@ __PACKAGE__->register_method( } ); +sub _flesh_and_emit_slots { + my ($conn, $e, $slots) = @_; + + for my $s (@$slots) { + my $start_time; + my $end_time; + if ($s->delivered) { + $start_time = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($s->delivered)); + $end_time = $start_time->clone->add(seconds => 90); # 90 seconds is arbitrary + } + my $holds = $e->search_action_hold_request([{ + usr => $s->patron->id, + current_shelf_lib => $s->org, + pickup_lib => $s->org, + shelf_time => {'!=' => undef}, + cancel_time => undef, + ($s->delivered) ? + ( + '-and' => [ { fulfillment_time => {'>=' => $start_time->strftime('%FT%T%z') } }, + { fulfillment_time => {'<=' => $end_time->strftime('%FT%T%z') } } ], + ) : + (fulfillment_time => undef), + },{ + flesh => 1, flesh_fields => {ahr => ['current_copy']}, + }]); + + my $rhrr_list = $e->search_reporter_hold_request_record( + {id => [ map { $_->id } @$holds ]} + ); + + my %bib_data = map { + ($_->id => $e->retrieve_metabib_wide_display_entry( $_->bib_record)) + } @$rhrr_list; + + $conn->respond({slot_id => $s->id, slot => $s, holds => $holds, bib_data_by_hold => \%bib_data}); + } +} + sub fetch_delivered { # returns appointments delivered TODAY my ($self, $conn, $authtoken, $org, $limit, $offset) = @_; @@ -166,7 +204,8 @@ sub fetch_delivered { # returns appointments delivered TODAY order_by => { acsp => {delivered => {direction => 'desc'}} } }]); - $conn->respond($_) for @$slots; + _flesh_and_emit_slots($conn, $e, $slots); + return undef; } __PACKAGE__->register_method( @@ -241,18 +280,8 @@ sub fetch_arrived { order_by => { acsp => 'arrival' } }]); - for my $s (@$slots) { - my $holds = $e->search_action_hold_request({ - usr => $s->patron->id, - current_shelf_lib => $s->org, - pickup_lib => $s->org, - shelf_time => {'!=' => undef}, - cancel_time => undef, - fulfillment_time => undef - }); - $conn->respond({slot_id => $s->id, slot => $s, holds => $holds}); - } + _flesh_and_emit_slots($conn, $e, $slots); return undef; } @@ -328,18 +357,7 @@ sub fetch_staged { order_by => { acsp => 'slot' } }]); - for my $s (@$slots) { - my $holds = $e->search_action_hold_request({ - usr => $s->patron->id, - current_shelf_lib => $s->org, - pickup_lib => $s->org, - shelf_time => {'!=' => undef}, - cancel_time => undef, - fulfillment_time => undef - }); - - $conn->respond({slot_id => $s->id, slot => $s, holds => $holds}); - } + _flesh_and_emit_slots($conn, $e, $slots); return undef; } @@ -423,28 +441,7 @@ sub fetch_to_be_staged { order_by => { acsp => 'slot' } }]); - for my $s (@$slots) { - my $holds = $e->search_action_hold_request([{ - usr => $s->patron->id, - current_shelf_lib => $s->org, - pickup_lib => $s->org, - shelf_time => {'!=' => undef}, - cancel_time => undef, - fulfillment_time => undef - },{ - flesh => 1, flesh_fields => {ahr => ['current_copy']}, - }]); - - my $rhrr_list = $e->search_reporter_hold_request_record( - {id => [ map { $_->id } @$holds ]} - ); - - my %bib_data = map { - ($_->id => $e->retrieve_metabib_wide_display_entry( $_->bib_record)) - } @$rhrr_list; - - $conn->respond({slot_id => $s->id, slot => $s, holds => $holds, bib_data_by_hold => \%bib_data}); - } + _flesh_and_emit_slots($conn, $e, $slots); return undef; } -- 2.11.0