Bug 8132: Adding a new message 'last_item_for_hold' blocking item deletion

If an item is the last one of a biblio that have biblio-level hold
placed on it, we should block the deletion.
It takes effect if the hold is found (W or T), to follow existing
behavior for item-level holds.
If we want to block deletion for any holds we should deal with it on a
separate bug report.

Test plan:
0/ Setup
Apply the patches
Create Biblio B1 with 1 item
Create Biblio B2 with 2 items
Create Biblio B3 with 1+ item
Create Biblio B4 with 1+ item
Create Biblio B5 with 1+ item
Place a biblio-level hold on B1 and B2
Place an item-level hold on B3 and B4
Confirm the item-level hold for the items of B3 to mark it waiting.

1/ Delete those 6 items in a batch
=> delete of item from B1 is blocked on first screen - only 1 item left
and there is a biblio-level hold on the record
=> delete of items from B2 is *not* blocked on first screen - One of
them will block the deletion, but so far we are not aware of that
situation
=> delete of item from B3 is blocked on first screen - there is a
waiting item-level hold placed on the item
=> delete of item from B4 is *not* blocked - there is a hold but it is
not found
=> delete of item from B5 is *not* - there is no reason to block its
deletion

Note that you can only select items from B2, B4 and B5

2/ Select them and confirm the deletion
=> Nothing happened and you get a message saying that one of the 2 items
from B2 is blocking the whole deletion process

3/ Remove the biblio-level hold from B2
4/ Repeat 1
=> The deletion has been effective!

=> Note that there is something a bit weird as we are blocking items
from a biblio that has biblio-level holds on it (not found), but we
do not blocking the deletion of an item with a waiting item-level hold

Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Jonathan Druart 2019-12-02 16:32:13 +01:00 committed by Martin Renvoize
parent 2363179198
commit e8414baf5b
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
2 changed files with 19 additions and 1 deletions

View file

@ -234,6 +234,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 {
@ -254,6 +256,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;
}

View file

@ -342,7 +342,7 @@ subtest 'pickup_locations' => sub {
};
subtest 'deletion' => sub {
plan tests => 11;
plan tests => 12;
$schema->storage->txn_begin;
@ -430,6 +430,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,