Delete volume on last copy setting
authorBill Erickson <berick@esilibrary.com>
Fri, 3 Jun 2011 17:21:37 +0000 (13:21 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 3 Jun 2011 17:21:37 +0000 (13:21 -0400)
When the last copy for a volume is deleted, go ahead and delete the
volume when this new setting is activated.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql

index 555e4b7..23f5c5b 100644 (file)
@@ -493,7 +493,27 @@ sub remove_empty_objects {
             my $evt = OpenILS::Application::Cat::BibCommon->delete_rec($editor, $vol->record);
             return $evt if $evt;
         }
-       }
+
+       } else {
+
+        # this may be the last copy attached to the volume.  
+
+        if($U->ou_ancestor_setting_value(
+                $editor->requestor->ws_ou, 'cat.volume.delete_on_empty', $editor)) {
+
+            # if this volume is "empty" and not mid-delete, delete it.
+            unless($U->is_true($vol->deleted) || $vol->isdeleted) {
+
+                my $copies = $editor->search_asset_copy(
+                    [{call_number => $vol->id, deleted => 'f'}, {limit => 1}], {idlist => 1});
+
+                if(!@$copies) {
+                    my $evt = $class->delete_volume($editor, $vol, $override, 0, 1);
+                    return $evt if $evt;
+                }
+            }
+        }
+    }
 
        return undef;
 }
index 5e294f1..f41ae3e 100644 (file)
@@ -8707,3 +8707,12 @@ INSERT INTO config.usr_setting_type
   oils_i18n_gettext('circ.collections.exempt', 'User is exempt from collections tracking/processing', 'cust', 'description'),
   'bool'
 );
+
+INSERT INTO config.org_unit_setting_type 
+( name, label, description, datatype ) VALUES 
+( 'cat.volume.delete_on_empty',
+  oils_i18n_gettext('cat.volume.delete_on_empty', 'Cat: Delete volume with last copy', 'coust', 'label'),
+  oils_i18n_gettext('cat.volume.delete_on_empty', 'Automatically delete a volume when the last linked copy is deleted', 'coust', 'description'),
+  'bool'
+);
+