@@ -, +, @@ item deletion --- Koha/Item.pm | 10 ++++++++++ t/db_dependent/Koha/Item.t | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) --- a/Koha/Item.pm +++ a/Koha/Item.pm @@ -220,6 +220,8 @@ returns 1 if the item is safe to delete, "linked_analytics" if the item has linked analytic records. +"last_item_for_hold" if the item is the last one on a record on which a biblio-level hold is placed + =cut sub safe_to_delete { @@ -240,6 +242,14 @@ sub safe_to_delete { return "linked_analytics" if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0; + return "last_item_for_hold" + if $self->biblio->items->count == 1 + && $self->biblio->holds->search( + { + itemnumber => undef, + } + )->count; + return 1; } --- a/t/db_dependent/Koha/Item.t +++ a/t/db_dependent/Koha/Item.t @@ -336,7 +336,7 @@ subtest 'pickup_locations' => sub { }; subtest 'deletion' => sub { - plan tests => 11; + plan tests => 12; $schema->storage->txn_begin; @@ -424,6 +424,14 @@ subtest 'deletion' => sub { } + { # last_item_for_hold + C4::Reserves::AddReserve($patron->branchcode, $patron->borrowernumber, $item->biblionumber ); + is( $item->safe_to_delete, 'last_item_for_hold', 'Item cannot be deleted if a biblio-level is placed on the biblio and there is only 1 item attached to the biblio' ); + + # With another item attached to the biblio, the item can be deleted + $builder->build_sample_item({ biblionumber => $item->biblionumber }); + } + is( $item->safe_to_delete, 1, --