View | Details | Raw Unified | Return to bug 40154
Collapse All | Expand All

(-)a/Koha/Item.pm (+5 lines)
Lines 345-350 returns 1 if the item is safe to delete, Link Here
345
345
346
"book_reserved" if the there are holds aganst the item, or
346
"book_reserved" if the there are holds aganst the item, or
347
347
348
"item_has_holds" if the item has holds,
349
348
"linked_analytics" if the item has linked analytic records.
350
"linked_analytics" if the item has linked analytic records.
349
351
350
"last_item_for_hold" if the item is the last one on a record on which a biblio-level hold is placed
352
"last_item_for_hold" if the item is the last one on a record on which a biblio-level hold is placed
Lines 367-372 sub safe_to_delete { Link Here
367
    $error //= "book_reserved"
369
    $error //= "book_reserved"
368
        if $self->holds->filter_by_found->count;
370
        if $self->holds->filter_by_found->count;
369
371
372
    $error //= "item_has_holds"
373
        if $self->holds->count;
374
370
    $error //= "linked_analytics"
375
    $error //= "linked_analytics"
371
        if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0;
376
        if C4::Items::GetAnalyticsCount( $self->itemnumber ) > 0;
372
377
(-)a/Koha/REST/V1/Items.pm (+1 lines)
Lines 140-145 sub delete { Link Here
140
                    { code => 'linked_analytics', description => 'The item has linked analytic records' },
140
                    { code => 'linked_analytics', description => 'The item has linked analytic records' },
141
                not_same_branch =>
141
                not_same_branch =>
142
                    { code => 'not_same_branch', description => 'The item is blocked by independent branches' },
142
                    { code => 'not_same_branch', description => 'The item is blocked by independent branches' },
143
                item_has_holds => { code => 'item_has_holds', description => 'The item has item level holds' },
143
            };
144
            };
144
145
145
            if ( any { $error->message eq $_ } keys %{$errors} ) {
146
            if ( any { $error->message eq $_ } keys %{$errors} ) {
(-)a/api/v1/swagger/paths/items.yaml (+1 lines)
Lines 158-163 Link Here
158
            * last_item_for_hold: The item is the last one on a record on which a biblio-level hold is placed
158
            * last_item_for_hold: The item is the last one on a record on which a biblio-level hold is placed
159
            * linked_analytics: The item has linked analytic records
159
            * linked_analytics: The item has linked analytic records
160
            * not_same_branch: The item is blocked by independent branches
160
            * not_same_branch: The item is blocked by independent branches
161
            * item_has_holds: The item has holds
161
        schema:
162
        schema:
162
          $ref: "../swagger.yaml#/definitions/error"
163
          $ref: "../swagger.yaml#/definitions/error"
163
      "500":
164
      "500":
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/batch_item_record_deletion.inc (+2 lines)
Lines 49-54 Link Here
49
                    <span>Item does not belong to your library</span>
49
                    <span>Item does not belong to your library</span>
50
                [% CASE "book_reserved" %]
50
                [% CASE "book_reserved" %]
51
                    <span>Item has a waiting hold</span>
51
                    <span>Item has a waiting hold</span>
52
                [% CASE "item_has_holds" %]
53
                    <span>Item has item level holds</span>
52
                [% CASE "linked_analytics" %]
54
                [% CASE "linked_analytics" %]
53
                    <span>Item has linked analytics</span>
55
                    <span>Item has linked analytics</span>
54
                [% CASE "last_item_for_hold" %]
56
                [% CASE "last_item_for_hold" %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc (+2 lines)
Lines 367-372 Link Here
367
                                            [% SET cannot_delete_reason = t("Item does not belong to your library") %]
367
                                            [% SET cannot_delete_reason = t("Item does not belong to your library") %]
368
                                        [% CASE "book_reserved" %]
368
                                        [% CASE "book_reserved" %]
369
                                            [% SET cannot_delete_reason = t("Item has a waiting hold") %]
369
                                            [% SET cannot_delete_reason = t("Item has a waiting hold") %]
370
                                        [% CASE "item_has_holds" %]
371
                                            [% SET cannot_delete_reason = t("Item has item level holds") %]
370
                                        [% CASE "linked_analytics" %]
372
                                        [% CASE "linked_analytics" %]
371
                                            [% SET cannot_delete_reason = t("Item has linked analytics") %]
373
                                            [% SET cannot_delete_reason = t("Item has linked analytics") %]
372
                                        [% CASE "last_item_for_hold" %]
374
                                        [% CASE "last_item_for_hold" %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (+1 lines)
Lines 95-100 Link Here
95
    [% 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 %]
95
    [% 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 %]
96
    [% IF ( book_on_loan ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item is checked out.</div>[% END %]
96
    [% IF ( book_on_loan ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item is checked out.</div>[% END %]
97
    [% IF ( book_reserved ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item has a waiting hold.</div>[% END %]
97
    [% IF ( book_reserved ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item has a waiting hold.</div>[% END %]
98
    [% IF ( item_has_holds ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: item has item level holds.</div>[% END %]
98
    [% IF ( not_same_branch ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: The items do not belong to your library.</div>[% END %]
99
    [% IF ( not_same_branch ) %]<div class="alert alert-warning"><strong>Cannot delete</strong>: The items do not belong to your library.</div>[% END %]
99
    [% IF ( linked_analytics ) %]
100
    [% IF ( linked_analytics ) %]
100
        <div class="alert alert-warning"><strong>Cannot delete</strong>: item has linked <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber | uri %]&amp;analyze=1">analytics.</a>.</div>
101
        <div class="alert alert-warning"><strong>Cannot delete</strong>: item has linked <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber | uri %]&amp;analyze=1">analytics.</a>.</div>
(-)a/t/db_dependent/Koha/Item.t (-2 / +25 lines)
Lines 1264-1270 subtest 'store check barcodes' => sub { Link Here
1264
};
1264
};
1265
1265
1266
subtest 'deletion' => sub {
1266
subtest 'deletion' => sub {
1267
    plan tests => 16;
1267
    plan tests => 18;
1268
1268
1269
    $schema->storage->txn_begin;
1269
    $schema->storage->txn_begin;
1270
1270
Lines 1345-1350 subtest 'deletion' => sub { Link Here
1345
        'IndependentBranches prevents deletion at another branch',
1345
        'IndependentBranches prevents deletion at another branch',
1346
    );
1346
    );
1347
1347
1348
    # item_has_holds
1349
    my $item_level_hold = $builder->build_object(
1350
        {
1351
            class => 'Koha::Holds',
1352
            value => {
1353
                biblionumber => $item->biblionumber,
1354
                itemnumber   => $item->itemnumber,
1355
                found        => undef,
1356
            }
1357
        }
1358
    );
1359
1360
    $item->discard_changes;
1361
    my $safe_to_delete = $item->safe_to_delete;
1362
    ok( !$safe_to_delete, 'Cannot delete item with item level holds' );
1363
    is(
1364
        @{ $safe_to_delete->messages }[0]->message,
1365
        'item_has_holds',
1366
        'Koha::Item->safe_to_delete reports item has item level holds',
1367
    );
1368
1369
    $item_level_hold->delete;
1370
1348
    # linked_analytics
1371
    # linked_analytics
1349
1372
1350
    {    # codeblock to limit scope of $module->mock
1373
    {    # codeblock to limit scope of $module->mock
Lines 2852-2858 subtest 'store() tests' => sub { Link Here
2852
            {
2875
            {
2853
                borrowernumber    => $patron->id,
2876
                borrowernumber    => $patron->id,
2854
                date              => '1970-01-01 14:00:01',
2877
                date              => '1970-01-01 14:00:01',
2855
                amountoutstanding => 0,
2878
                amountoutstanding =>  0,
2856
                amount            => -5,
2879
                amount            => -5,
2857
                interface         => 'commandline',
2880
                interface         => 'commandline',
2858
                credit_type_code  => 'PAYMENT'
2881
                credit_type_code  => 'PAYMENT'
(-)a/t/db_dependent/api/v1/items.t (-2 / +2 lines)
Lines 357-363 subtest 'get() tests' => sub { Link Here
357
357
358
subtest 'delete() tests' => sub {
358
subtest 'delete() tests' => sub {
359
359
360
    plan tests => 23;
360
    plan tests => 26;
361
361
362
    $schema->storage->txn_begin;
362
    $schema->storage->txn_begin;
363
363
Lines 398-403 subtest 'delete() tests' => sub { Link Here
398
        },
398
        },
399
        linked_analytics => { code => 'linked_analytics', description => 'The item has linked analytic records' },
399
        linked_analytics => { code => 'linked_analytics', description => 'The item has linked analytic records' },
400
        not_same_branch  => { code => 'not_same_branch', description => 'The item is blocked by independent branches' },
400
        not_same_branch  => { code => 'not_same_branch', description => 'The item is blocked by independent branches' },
401
        item_has_holds   => { code => 'item_has_holds',  description => 'The item has item level holds' },
401
    };
402
    };
402
403
403
    $fail = 1;
404
    $fail = 1;
404
- 

Return to bug 40154