From 734c639c550ef58a583fb8d4ef9b59c02714c7b5 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 28 Feb 2020 10:32:16 -0500 Subject: [PATCH] Bug 24857: Delete a volume when the last item on that volume is deleted --- C4/Items.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/C4/Items.pm b/C4/Items.pm index 925afc2397..bd7b299ac7 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -611,6 +611,13 @@ sub DelItem { # If there is no biblionumber for the given itemnumber, there is nothing to delete return 0 unless $biblionumber; + # Find the volume_item now, it will be deleted when the item is deleted + my $volume_id; + if ( C4::Context->preference('EnableVolumes') ) { + my $volume_item = Koha::Biblio::Volume::Items->find({ itemnumber => $itemnumber }); + $volume_id = $volume_item ? $volume_item->volume_id : undef; + } + # FIXME check the item has no current issues my $deleted = _koha_delete_item( $itemnumber ); @@ -618,6 +625,13 @@ sub DelItem { _after_item_action_hooks({ action => 'delete', item_id => $itemnumber }); + # If this item is the last item on a volume, delete the volume as well + if ( $volume_id ) { + my $volume = Koha::Biblio::Volumes->find( $volume_id ); + my @volume_items = $volume->items(); + $volume->delete unless @volume_items; + } + #search item field code logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); return $deleted; -- 2.21.1 (Apple Git-122.3)