Bug 40154: prevent deletion of items with holds
This patch prevents deletion of items that have item level holds on
them.
Test plan:
1. Create an item level hold.
2. Delete the item using alternative A or B:
A. Open the biblios Detail-view -> From the toolbar, open
"Edit"-dropdown menu -> Manage items -> Delete the item that has
an item level hold attached to it from "Actions"-dropdown menu
B. Open the biblios Detail-view -> Select the item that has an item
level hold attached to it -> Click "Delete selected items" ->
Confirm deletion
3. Notice that the item is deleted without any warning and the item
level hold has disappeared.
4. Apply this patch.
5. Repeat steps 1-3.
6. Notice that the item cannot be deleted and a warning is shown.
7. prove t/db_dependent/Koha/Item.t
8. Run the REST API tests: prove t/db_dependent/api/v1/items.t
Sponsored-by: Koha-Suomi Oy
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
57dbd3677a
commit
9445ffc9aa
|
|
@ -345,6 +345,8 @@ returns 1 if the item is safe to delete,
|
|||
|
||||
"book_reserved" if the there are holds aganst the item, or
|
||||
|
||||
"item_has_holds" if the item has holds,
|
||||
|
||||
"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
|
||||
|
|
@ -367,6 +369,9 @@ sub safe_to_delete {
|
|||
$error //= "book_reserved"
|
||||
if $self->holds->filter_by_found->count;
|
||||
|
||||
$error //= "item_has_holds"
|
||||
if $self->holds->count;
|
||||
|
||||
$error //= "linked_analytics"
|
||||
if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ sub delete {
|
|||
{ code => 'linked_analytics', description => 'The item has linked analytic records' },
|
||||
not_same_branch =>
|
||||
{ code => 'not_same_branch', description => 'The item is blocked by independent branches' },
|
||||
item_has_holds => { code => 'item_has_holds', description => 'The item has item level holds' },
|
||||
};
|
||||
|
||||
if ( any { $error->message eq $_ } keys %{$errors} ) {
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@
|
|||
* last_item_for_hold: The item is the last one on a record on which a biblio-level hold is placed
|
||||
* linked_analytics: The item has linked analytic records
|
||||
* not_same_branch: The item is blocked by independent branches
|
||||
* item_has_holds: The item has holds
|
||||
schema:
|
||||
$ref: "../swagger.yaml#/definitions/error"
|
||||
"500":
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@
|
|||
<span>Item does not belong to your library</span>
|
||||
[% CASE "book_reserved" %]
|
||||
<span>Item has a waiting hold</span>
|
||||
[% CASE "item_has_holds" %]
|
||||
<span>Item has item level holds</span>
|
||||
[% CASE "linked_analytics" %]
|
||||
<span>Item has linked analytics</span>
|
||||
[% CASE "last_item_for_hold" %]
|
||||
|
|
|
|||
|
|
@ -378,6 +378,8 @@
|
|||
[% SET cannot_delete_reason = t("Item does not belong to your library") %]
|
||||
[% CASE "book_reserved" %]
|
||||
[% SET cannot_delete_reason = t("Item has a waiting hold") %]
|
||||
[% CASE "item_has_holds" %]
|
||||
[% SET cannot_delete_reason = t("Item has item level holds") %]
|
||||
[% CASE "linked_analytics" %]
|
||||
[% SET cannot_delete_reason = t("Item has linked analytics") %]
|
||||
[% CASE "last_item_for_hold" %]
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@
|
|||
[% IF ( no_next_barcode ) %]<div class="alert alert-warning"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div>[% END %]
|
||||
[% IF ( book_on_loan ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item is checked out.</div>[% END %]
|
||||
[% IF ( book_reserved ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item has a waiting hold.</div>[% END %]
|
||||
[% IF ( item_has_holds ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item has item level holds.</div>[% END %]
|
||||
[% IF ( not_same_branch ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: The items do not belong to your library.</div>[% END %]
|
||||
[% IF ( linked_analytics ) %]
|
||||
<div class="alert alert-warning"><strong>Cannot delete</strong>: item has linked <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber | uri %]&analyze=1">analytics.</a>.</div>
|
||||
|
|
|
|||
|
|
@ -1275,7 +1275,7 @@ subtest 'store check barcodes' => sub {
|
|||
};
|
||||
|
||||
subtest 'deletion' => sub {
|
||||
plan tests => 16;
|
||||
plan tests => 18;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
|
@ -1356,6 +1356,29 @@ subtest 'deletion' => sub {
|
|||
'IndependentBranches prevents deletion at another branch',
|
||||
);
|
||||
|
||||
# item_has_holds
|
||||
my $item_level_hold = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Holds',
|
||||
value => {
|
||||
biblionumber => $item->biblionumber,
|
||||
itemnumber => $item->itemnumber,
|
||||
found => undef,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$item->discard_changes;
|
||||
my $safe_to_delete = $item->safe_to_delete;
|
||||
ok( !$safe_to_delete, 'Cannot delete item with item level holds' );
|
||||
is(
|
||||
@{ $safe_to_delete->messages }[0]->message,
|
||||
'item_has_holds',
|
||||
'Koha::Item->safe_to_delete reports item has item level holds',
|
||||
);
|
||||
|
||||
$item_level_hold->delete;
|
||||
|
||||
# linked_analytics
|
||||
|
||||
{ # codeblock to limit scope of $module->mock
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ subtest 'get() tests' => sub {
|
|||
|
||||
subtest 'delete() tests' => sub {
|
||||
|
||||
plan tests => 23;
|
||||
plan tests => 26;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
|
@ -414,6 +414,7 @@ subtest 'delete() tests' => sub {
|
|||
},
|
||||
linked_analytics => { code => 'linked_analytics', description => 'The item has linked analytic records' },
|
||||
not_same_branch => { code => 'not_same_branch', description => 'The item is blocked by independent branches' },
|
||||
item_has_holds => { code => 'item_has_holds', description => 'The item has item level holds' },
|
||||
};
|
||||
|
||||
$fail = 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue