LP#1879983: A/T components of Curbside
authorMike Rylander <mrylander@gmail.com>
Tue, 19 May 2020 19:13:57 +0000 (15:13 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 15 Sep 2020 20:20:40 +0000 (16:20 -0400)
This commit adds a reactor and validator for automating parts of the
basic Curbside workflows:

* Curbside validator: check whether curbside is enabled at the org unit
  applicable an A/T event's target, which could be a user, org unit,
  curbside appointment, or hold request.
* CurbsideSlot reactor: Creates a curbside appointment slot at the hold
  pickup library when a hold becomes ready for pickup, if one does not
  exist. This is meant to be triggered by the hold.available hook.
  Appointments created by this reactor do not have an appointment time
  set, as that is meant to be supplied by the patron or a staff member
  acting on behalf of the patron.

In addition to Mike Rylander, significant contributions to this
patch were made by Jason Boyer.

Sponsored-by: PaILS

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Jason Boyer <jboyer@equinoxinitiative.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>

Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/CurbsideSlot.pm [new file with mode: 0644]
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator/Curbside.pm [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/CurbsideSlot.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/CurbsideSlot.pm
new file mode 100644 (file)
index 0000000..bb07c3f
--- /dev/null
@@ -0,0 +1,51 @@
+package OpenILS::Application::Trigger::Reactor::CurbsideSlot;
+use base 'OpenILS::Application::Trigger::Reactor';
+use strict; use warnings;
+use OpenILS::Utils::CStoreEditor q/:funcs/;
+use OpenILS::Application::AppUtils;
+my $U = "OpenILS::Application::AppUtils";
+
+$Data::Dumper::Indent = 0;
+
+
+sub ABOUT {
+    return <<ABOUT;
+    
+    Creates a curbside appointment slot at the hold pickup library when
+    a hold becomes ready for pickup, if one does not exist.
+
+ABOUT
+}
+
+sub handler {
+    my $self = shift;
+    my $env = shift;
+    my $e = new_editor(xact => 1);
+
+    my $h = $$env{target};
+
+    # see if there's an undelivered appointment in the future
+    my $slot = $e->search_action_curbside({
+        patron => $h->usr,
+        org => $h->pickup_lib,
+        delivered => undef
+    });
+
+    if (!@$slot) {
+        $slot = Fieldmapper::action::curbside->new;
+        $slot->org($h->pickup_lib);
+        $slot->patron($h->usr);
+        $e->create_action_curbside($slot);
+        $e->commit;
+
+        my $ses = OpenSRF::AppSession->create('open-ils.trigger');
+        $ses->request('open-ils.trigger.event.autocreate', 'hold.offer_curbside', $h, $h->pickup_lib);
+
+    } else {
+        $e->rollback;
+    }
+
+    return 1;
+}
+
+1;
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator/Curbside.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Validator/Curbside.pm
new file mode 100644 (file)
index 0000000..3fab8ff
--- /dev/null
@@ -0,0 +1,29 @@
+package OpenILS::Application::Trigger::Validator::Curbside;
+use strict; use warnings;
+use OpenILS::Application::AppUtils;
+my $U = 'OpenILS::Application::AppUtils';
+
+sub handler {
+    my ($self, $env) = @_;
+    my $org;
+
+    # support a few different target types
+    if ($env->{target}->isa('Fieldmapper::action::curbside')) {
+        $org = $env->{target}->org;
+    } elsif ($env->{target}->isa('Fieldmapper::action::hold_request')) {
+        $org = $env->{target}->pickup_lib;
+    } elsif ($env->{target}->isa('Fieldmapper::actor::usr')) {
+        $org = $env->{target}->home_ou;
+    } elsif ($env->{target}->isa('Fieldmapper::actor::org_unit')) {
+        $org = $env->{target}->id;
+    }
+
+    return 0 unless (defined $org);
+
+    $org = $org->id if ref($org); # somehow we got a fleshed org object on the target
+    return $U->is_true(
+        $U->ou_ancestor_setting_value($org, 'circ.curbside')
+    );
+}
+
+1;