LP#1634244 - prevent bibs from being deleted when they have on-order, pending-order...
authorRogan Hamby <rogan.hamby@gmail.com>
Fri, 19 Apr 2019 19:39:57 +0000 (15:39 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Thu, 1 Aug 2019 11:34:31 +0000 (07:34 -0400)
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm

index 362fff5..2163696 100644 (file)
        <event code='1881' textcode='PERMISSION_GRP_PENALTY_THRESHOLD_NOT_FOUND'>
                <desc xml:lang='en-US'>The requested permission_grp_penalty_threshold was not found</desc>
        </event>
-
+    <event code='1882' textcode='RECORD_REFERENCED_BY_LINEITEM'>
+        <desc xml:lang="en-US">The selected bib record has an open lineitem order referencing it.</desc>
+    </event>
 
        <event code='1700' textcode='NON_CAT_TYPE_EXISTS'>
                <desc xml:lang="en-US"> The non-cataloged type object already exists </desc>
index 8316337..4c4d977 100644 (file)
@@ -1296,6 +1296,17 @@ sub delete_bib_record {
     return $e->die_event unless $e->allowed('DELETE_RECORD', $e->requestor->ws_ou);
     my $vols = $e->search_asset_call_number({record=>$rec_id, deleted=>'f'});
     return OpenILS::Event->new('RECORD_NOT_EMPTY', payload=>$rec_id) if @$vols;
+    my $acq_li_count = $e->json_query({
+        select => {jub => [{column => 'id', transform => 'count'}]},
+    from => 'jub',
+    where => {
+        '+jub' => {
+                 eg_bib_id => $rec_id,
+                 state => ['new','pending-order','on-order']
+            }
+        }
+    })->[0];
+    return OpenILS::Event->new('RECORD_REFERENCED_BY_LINEITEM', payload => $rec_id) if ($acq_li_count->{id} > 0);
     my $evt = OpenILS::Application::Cat::BibCommon->delete_rec($e, $rec_id);
     if($evt) { $e->rollback; return $evt; }   
     $e->commit;