teach copy alerts how to automatically generate certain overrides
authorGalen Charlton <gmc@esilibrary.com>
Wed, 31 Aug 2016 21:02:17 +0000 (17:02 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 31 Jul 2017 14:12:51 +0000 (10:12 -0400)
When a new-style copy alert type is active but supressed, any
system-generated events of that type should be recorded but
not present a pop-up. In some cases, an older-style circ event
make get generated; this patch supplies a way for the new copy
alerts to override the old-style events without having
to sprinkle a bunch of special checks.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

index 74713c1..f74693c 100644 (file)
@@ -40,6 +40,12 @@ my $MK_ENV_FLESH = {
     flesh_fields => {acp => ['call_number','parts','floating'], acn => ['record']}
 };
 
+# table of cases where suppressing a system-generated copy alerts
+# should generate an override of an old-style event
+my %COPY_ALERT_OVERRIDES = (
+    "CLAIMSRETURNED\tCHECKOUT" => 'CIRC_CLAIMS_RETURNED',
+);
+
 sub initialize {}
 
 __PACKAGE__->register_method(
@@ -396,6 +402,7 @@ my @AUTOLOAD_FIELDS = qw/
     new_copy_alerts
     user_copy_alerts
     system_copy_alerts
+    overrides_per_copy_alerts
     next_copy_status
     copy_state
     patron
@@ -782,6 +789,11 @@ sub generate_system_copy_alerts {
     }
 
     my @alerts;
+    
+    # keep track of conditions corresponding to suppressed
+    # system alerts, as these may be used to overridee
+    # certain old-style-events
+    my %auto_override_conditions = ();
     foreach my $t (@final_types) {
         $t->next_status([$U->unique_unnested_numbers($t->next_status)])
             if ($t->next_status);
@@ -802,10 +814,25 @@ sub generate_system_copy_alerts {
         $alert->alert_type($t->clone);
 
         push(@{$self->next_copy_status}, @{$t->next_status}) if ($t->next_status);
+        if (grep {$_->alert_type == $t->id} @$suppressions) {
+            $auto_override_conditions{join("\t", $t->state, $t->event)} = 1;
+        }
         push(@alerts, $alert) unless (grep {$_->alert_type == $t->id} @$suppressions);
     }
 
     $self->system_copy_alerts(\@alerts);
+    $self->overrides_per_copy_alerts(\%auto_override_conditions);
+}
+
+sub add_overrides_from_system_copy_alerts {
+    my $self = shift;
+
+    foreach my $condition (keys %{$self->overrides_per_copy_alerts()}) {
+        if (exists $COPY_ALERT_OVERRIDES{$condition}) {
+            $self->override(1);
+            push @{$self->override_args->{events}}, $COPY_ALERT_OVERRIDES{$condition};
+        }
+    }
 }
 
 sub mk_env {
@@ -872,6 +899,7 @@ sub mk_env {
             );
 
             $self->generate_system_copy_alerts;
+            $self->add_overrides_from_system_copy_alerts;
             $self->collect_user_copy_alerts;
             $self->filter_user_copy_alerts;