Delete volume on last copy setting
authorBill Erickson <berick@esilibrary.com>
Fri, 3 Jun 2011 17:21:37 +0000 (13:21 -0400)
committerJason Etheridge <jason@esilibrary.com>
Fri, 24 Jun 2011 15:15:18 +0000 (11:15 -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>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/xul/staff_client/server/cat/copy_browser.js
Open-ILS/xul/staff_client/server/circ/copy_status.js
Open-ILS/xul/staff_client/server/locale/en-US/cat.properties
Open-ILS/xul/staff_client/server/locale/en-US/circ.properties

index 555e4b7..5ac2a1d 100644 (file)
@@ -200,7 +200,10 @@ sub update_copy {
 
        $logger->info("vol-update: updating copy ".$copy->id);
        my $orig_copy = $editor->retrieve_asset_copy($copy->id);
-       my $orig_vol  = $editor->retrieve_asset_call_number($copy->call_number);
+
+    # Call-number may have changed, find the original
+    my $orig_vol_id = $editor->json_query({select => {acp => ['call_number']}, from => 'acp', where => {id => $copy->id}});
+    my $orig_vol  = $editor->retrieve_asset_call_number($orig_vol_id->[0]->{call_number});
 
        $copy->editor($editor->requestor->id);
        $copy->edit_date('now');
@@ -493,7 +496,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 a134560..191da0f 100644 (file)
@@ -8748,3 +8748,11 @@ INSERT INTO config.org_unit_setting_type ( name, label, description, datatype )
     'interval'
 );
 
+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'
+);
+
index 7a734fc..9122655 100644 (file)
@@ -683,27 +683,42 @@ cat.copy_browser.prototype = {
                                             document.getElementById('commonStrings').getString('common.confirm')
                                     );
 
-                                    if (r == 0) {
+                                    if (r == 0) { // delete vols
                                         for (var i = 0; i < list.length; i++) {
                                             list[i].isdeleted('1');
                                         }
-                                        var robj = obj.network.simple_request(
-                                            'FM_ACN_TREE_UPDATE', 
-                                            [ ses(), list, true ],
-                                            null,
-                                            {
-                                                'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'),
-                                                'overridable_events' : [
-                                                ]
-                                            }
-                                        );
-                                        if (robj == null) throw(robj);
-                                        if (typeof robj.ilsevent != 'undefined') {
-                                            if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
-                                                alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'));
-                                                return;
+                                        var params = {};
+                                        loop: while(true) {
+                                            var robj = obj.network.simple_request(
+                                                'FM_ACN_TREE_UPDATE', 
+                                                [ ses(), list, true, params ],
+                                                null,
+                                                {
+                                                    'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'),
+                                                    'overridable_events' : [
+                                                    ]
+                                                }
+                                            );
+                                            if (robj == null) throw(robj);
+                                            if (typeof robj.ilsevent != 'undefined') {
+                                                if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
+                                                    var r2 = obj.error.yns_alert(
+                                                        document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'),
+                                                        document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'),
+                                                        document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain.confirm'),
+                                                        document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain.cancel'),
+                                                        null,
+                                                        document.getElementById('commonStrings').getString('common.confirm')
+                                                    );
+                                                    if (r2 == 0) { // delete vols and copies
+                                                        params.force_delete_copies = true;
+                                                        continue loop;
+                                                    }
+                                                } else {
+                                                    if (robj.ilsevent != 0) throw(robj);
+                                                }
                                             }
-                                            if (robj.ilsevent != 0) throw(robj);
+                                            break loop;
                                         }
                                         obj.refresh_list();
                                     }
index 9ff0201..f2816c1 100644 (file)
@@ -802,23 +802,38 @@ circ.copy_status.prototype = {
                                     for (var i = 0; i < list.length; i++) {
                                         list[i].isdeleted('1');
                                     }
-                                    var robj = obj.network.simple_request(
-                                        'FM_ACN_TREE_UPDATE', 
-                                        [ ses(), list, true ],
-                                        null,
-                                        {
-                                            'title' : document.getElementById('circStrings').getString('staff.circ.copy_status.delete_volumes.override'),
-                                            'overridable_events' : [
-                                            ]
-                                        }
-                                    );
-                                    if (robj == null) throw(robj);
-                                    if (typeof robj.ilsevent != 'undefined') {
-                                        if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
-                                            alert(document.getElementById('circStrings').getString('staff.circ.copy_status.delete_volumes.delete_copies'));
-                                            return;
+                                    var params = {};
+                                    loop: while(true) {
+                                        var robj = obj.network.simple_request(
+                                            'FM_ACN_TREE_UPDATE', 
+                                            [ ses(), list, true, params ],
+                                            null,
+                                            {
+                                                'title' : document.getElementById('circStrings').getString('staff.circ.copy_status.delete_volumes.override'),
+                                                'overridable_events' : [
+                                                ]
+                                            }
+                                        );
+                                        if (robj == null) throw(robj);
+                                        if (typeof robj.ilsevent != 'undefined') {
+                                            if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) {
+                                                var r2 = obj.error.yns_alert(
+                                                    document.getElementById('circStrings').getString('staff.circ.copy_status.delete_volumes.delete_copies'),
+                                                    document.getElementById('circStrings').getString('staff.circ.copy_status.delete_volumes.title'),
+                                                    document.getElementById('circStrings').getString('staff.circ.copy_status.delete_volumes.delete_copies.confirm'),
+                                                    document.getElementById('circStrings').getString('staff.circ.copy_status.delete_volumes.delete_copies.cancel'),
+                                                    null,
+                                                    document.getElementById('commonStrings').getString('common.confirm')
+                                                );
+                                                if (r2 == 0) { // delete vols and copies
+                                                    params.force_delete_copies = true;
+                                                    continue loop;
+                                                }
+                                            } else {
+                                                if (robj.ilsevent != 0) { throw(robj); }
+                                            }
                                         }
-                                        if (robj.ilsevent != 0) { throw(robj); }
+                                        break loop;
                                     }
                                     alert(document.getElementById('circStrings').getString('staff.circ.copy_status.delete_volumes.success'));
                                 }
index 0287758..f75c4e9 100644 (file)
@@ -56,7 +56,9 @@ staff.cat.copy_browser.delete_volume.title=Delete Volumes?
 staff.cat.copy_browser.delete_volume.delete=Delete
 staff.cat.copy_browser.delete_volume.cancel=Cancel
 staff.cat.copy_browser.delete_volume.override=Override Delete Failure?
-staff.cat.copy_browser.delete_volume.copies_remain=You must delete all the copies on the volume before you may delete the volume itself.
+staff.cat.copy_browser.delete_volume.copies_remain=You must delete all the items on the volume before you may delete the volume itself.
+staff.cat.copy_browser.delete_volume.copies_remain.confirm=Delete Volume and Items
+staff.cat.copy_browser.delete_volume.copies_remain.cancel=Cancel Delete
 staff.cat.copy_browser.delete_volume.exception=copy browser -> delete volumes
 staff.cat.copy_browser.mark_library.alert=Library + Record marked as Volume Transfer Destination
 staff.cat.copy_browser.mark_library.prompt=Choose just one Library to mark as Volume Transfer Destination
index 66ed6a3..15f4d37 100644 (file)
@@ -134,7 +134,9 @@ staff.circ.copy_status.delete_volumes.title=Delete Volumes?
 staff.circ.copy_status.delete_volumes.delete=Delete
 staff.circ.copy_status.delete_volumes.cancel=Cancel
 staff.circ.copy_status.delete_volumes.override=Override Delete Failure?
-staff.circ.copy_status.delete_volumes.delete_copies=You must delete all the copies on the volume before you may delete the volume itself.
+staff.circ.copy_status.delete_volumes.delete_copies=You must delete all the items on the volume before you may delete the volume itself.
+staff.circ.copy_status.delete_volumes.delete_copies.confirm=Delete Volume and Items
+staff.circ.copy_status.delete_volumes.delete_copies.cancel=Cancel Delete
 staff.circ.copy_status.delete_volumes.success=Volumes deleted.
 staff.circ.copy_status.mark_volume.status=Volume marked as Item Transfer Destination
 staff.circ.copy_status.mark_volume.prompt=Choose just one Volume to mark as Item Transfer Destination