From: Galen Charlton Date: Wed, 5 Jul 2017 21:27:51 +0000 (-0400) Subject: webstaff serials: delete last issuance if it has no items left X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=253275c2bbfcb38ac126df64b37a86c604632c4c;p=working%2FEvergreen.git webstaff serials: delete last issuance if it has no items left Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index c645bb2e77..fed5604a28 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -257,6 +257,7 @@ sub fleshed_item_alter { my %found_sdist_ids; my %found_sstr_ids; + my %siss_to_potentially_delete; for my $item (@$items) { my $sstr_id = ref $item->stream ? $item->stream->id : $item->stream; if (!exists($found_sstr_ids{$sstr_id})) { @@ -279,6 +280,8 @@ sub fleshed_item_alter { $item->edit_date('now'); 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); } elsif( $item->isnew ) { # TODO: reconsider this @@ -299,6 +302,31 @@ sub fleshed_item_alter { $editor->rollback; return $evt; } + if( %siss_to_potentially_delete ) { + foreach my $id (keys %siss_to_potentially_delete) { + my $issuance = $editor->retrieve_serial_issuance([ + $id, { + "flesh" => 1, "flesh_fields" => { + "siss" => ["items"], + } + } + ]); + unless ($issuance) { + $logger->warn("fleshed item-alter failed to retrieve issuance $id to potenitally delete"); + $editor->rollback; + return $editor->die_event; + } + unless (@{ $issuance->items }) { + $logger->info("fleshed item-alter deleting issuance $id as it has no items left"); + $evt = _delete_siss( $editor, $override, $issuance); + if( $evt ) { + $logger->info("fleshed item-alter failed with event: ".OpenSRF::Utils::JSON->perl2JSON($evt)); + $editor->rollback; + return $evt; + } + } + } + } $logger->debug("item-alter: done updating item batch"); $editor->commit; $logger->info("fleshed item-alter successfully updated ".scalar(@$items)." items"); 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 244f3bee9a..9349ffe38a 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 @@ -92,6 +92,7 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByF var obj = egCore.idl.fromHash('sitem',i); obj.isdeleted(1); obj.stream(obj.stream().id); // API wants scalar or FM object + obj.issuance(obj.issuance().id); list.push(obj); });