LP#1414197 Serial Item Delete Improvements
authorDan Wells <dbw2@calvin.edu>
Fri, 6 Jul 2018 15:47:42 +0000 (11:47 -0400)
committerKathy Lussier <klussier@masslnc.org>
Wed, 25 Jul 2018 14:21:13 +0000 (10:21 -0400)
If a serial item is received, then deleted without any further status,
it can leave the system in an inconsistent state:

1) If from a multi-item unit, the unit contents are not updated.
2) If from a single-item unit, the unit is not deleted.
3) If the last holding of its kind, holdings summaries are not updated.

Since 'resetting' items has all the necessary logic to handle the above
needs, this commit runs each deleted item through the reset code before
doing the actual delete.  This also gives the benefit of keeping the
logic centralized for future fixes/enhancements.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>

Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js

index f0b10d2..dfe9878 100644 (file)
@@ -258,6 +258,7 @@ sub fleshed_item_alter {
     my %found_sdist_ids;
     my %found_sstr_ids;
     my %siss_to_potentially_delete;
+    my @deleted_items;
     for my $item (@$items) {
         my $sstr_id = ref $item->stream ? $item->stream->id : $item->stream;
         if (!exists($found_sstr_ids{$sstr_id})) {
@@ -282,7 +283,9 @@ sub fleshed_item_alter {
         if( $item->isdeleted ) {
             my $siss_id = ref $item->issuance ? $item->issuance->id : $item->issuance;
             $siss_to_potentially_delete{$siss_id}++;
-            $evt = _delete_sitem( $editor, $override, $item);
+            # We don't want to do a bunch of resetting churn for multiple items
+            # in the same unit/dist, so just gather ids for now
+            push(@deleted_items, $item);
         } elsif( $item->isnew ) {
             # TODO: reconsider this
             # if the item has a new issuance, create the issuance first
@@ -297,6 +300,25 @@ sub fleshed_item_alter {
         }
     }
 
+    if (@deleted_items) {
+        # First, reset as a batch any assigned to units.  This cleans up units
+        # and rebuilds summaries as needed
+        #
+        # XXX: if we ever add a 'deleted' flag to items, we may want to
+        # preserve rather than reset the received information
+        my @unit_items = grep {$_->unit} @deleted_items;
+        my $reset_info = $self->method_lookup('open-ils.serial.reset_items')->run($auth, \@unit_items) if @unit_items;
+
+        # Next, do the actual deletes, unless we got an event
+        if ($U->event_code($reset_info)) {
+            $evt = $reset_info;
+        } else {
+            foreach my $item (@deleted_items) {
+                $evt = _delete_sitem( $editor, $override, $item);
+            }
+        }
+    }
+
     if( $evt ) {
         $logger->info("fleshed item-alter failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt));
         $editor->rollback;
index 5d9d376..25a2836 100644 (file)
@@ -89,10 +89,8 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByF
         var list = [];
 
         angular.forEach(items, function (i) {
-            var obj = egCore.idl.fromHash('sitem',i);
+            var obj = egSerialsCoreSvc.itemMap[i.id];
             obj.isdeleted(1);
-            obj.stream(obj.stream().id); // API wants scalar or FM object
-            obj.issuance(obj.issuance().id);
             list.push(obj);
         });