From: Bill Erickson Date: Fri, 3 Jun 2011 17:21:37 +0000 (-0400) Subject: Delete volume on last copy setting X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6c3b571395aff3551d9fafff7e8a6654893f0996;p=evergreen%2Fpines.git Delete volume on last copy setting 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 Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm index 555e4b791b..5ac2a1d0af 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/AssetCommon.pm @@ -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; } diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index a1345600ae..191da0fad5 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -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' +); + diff --git a/Open-ILS/xul/staff_client/server/cat/copy_browser.js b/Open-ILS/xul/staff_client/server/cat/copy_browser.js index 7a734fc9dc..9122655808 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_browser.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_browser.js @@ -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(); } diff --git a/Open-ILS/xul/staff_client/server/circ/copy_status.js b/Open-ILS/xul/staff_client/server/circ/copy_status.js index 9ff0201231..f2816c12e7 100644 --- a/Open-ILS/xul/staff_client/server/circ/copy_status.js +++ b/Open-ILS/xul/staff_client/server/circ/copy_status.js @@ -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')); } diff --git a/Open-ILS/xul/staff_client/server/locale/en-US/cat.properties b/Open-ILS/xul/staff_client/server/locale/en-US/cat.properties index 0287758f94..f75c4e9ca4 100644 --- a/Open-ILS/xul/staff_client/server/locale/en-US/cat.properties +++ b/Open-ILS/xul/staff_client/server/locale/en-US/cat.properties @@ -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 diff --git a/Open-ILS/xul/staff_client/server/locale/en-US/circ.properties b/Open-ILS/xul/staff_client/server/locale/en-US/circ.properties index 66ed6a376f..15f4d3745b 100644 --- a/Open-ILS/xul/staff_client/server/locale/en-US/circ.properties +++ b/Open-ILS/xul/staff_client/server/locale/en-US/circ.properties @@ -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