From 949a9af6d022959f2d394cb927269b3ef74b6df7 Mon Sep 17 00:00:00 2001 From: Dan Wells Date: Fri, 6 Jul 2018 11:47:42 -0400 Subject: [PATCH] LP#1414197 Serial Item Delete Improvements 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 Signed-off-by: Kathy Lussier --- .../lib/OpenILS/Application/Serial.pm | 24 ++++++++++++++++++- .../serials/directives/view-items-grid.js | 4 +--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index f0b10d2cbe..dfe98789b0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -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; diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js b/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js index 5d9d376c56..25a28362d5 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js +++ b/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js @@ -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); }); -- 2.43.2