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 378-383 Link Here
378
                                            [% SET cannot_delete_reason = t("Item does not belong to your library") %]
378
                                            [% SET cannot_delete_reason = t("Item does not belong to your library") %]
379
                                        [% CASE "book_reserved" %]
379
                                        [% CASE "book_reserved" %]
380
                                            [% SET cannot_delete_reason = t("Item has a waiting hold") %]
380
                                            [% SET cannot_delete_reason = t("Item has a waiting hold") %]
381
                                        [% CASE "item_has_holds" %]
382
                                            [% SET cannot_delete_reason = t("Item has item level holds") %]
381
                                        [% CASE "linked_analytics" %]
383
                                        [% CASE "linked_analytics" %]
382
                                            [% SET cannot_delete_reason = t("Item has linked analytics") %]
384
                                            [% SET cannot_delete_reason = t("Item has linked analytics") %]
383
                                        [% CASE "last_item_for_hold" %]
385
                                        [% 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 1275-1281 subtest 'store check barcodes' => sub { Link Here
1275
};
1275
};
1276
1276
1277
subtest 'deletion' => sub {
1277
subtest 'deletion' => sub {
1278
    plan tests => 16;
1278
    plan tests => 18;
1279
1279
1280
    $schema->storage->txn_begin;
1280
    $schema->storage->txn_begin;
1281
1281
Lines 1356-1361 subtest 'deletion' => sub { Link Here
1356
        'IndependentBranches prevents deletion at another branch',
1356
        'IndependentBranches prevents deletion at another branch',
1357
    );
1357
    );
1358
1358
1359
    # item_has_holds
1360
    my $item_level_hold = $builder->build_object(
1361
        {
1362
            class => 'Koha::Holds',
1363
            value => {
1364
                biblionumber => $item->biblionumber,
1365
                itemnumber   => $item->itemnumber,
1366
                found        => undef,
1367
            }
1368
        }
1369
    );
1370
1371
    $item->discard_changes;
1372
    my $safe_to_delete = $item->safe_to_delete;
1373
    ok( !$safe_to_delete, 'Cannot delete item with item level holds' );
1374
    is(
1375
        @{ $safe_to_delete->messages }[0]->message,
1376
        'item_has_holds',
1377
        'Koha::Item->safe_to_delete reports item has item level holds',
1378
    );
1379
1380
    $item_level_hold->delete;
1381
1359
    # linked_analytics
1382
    # linked_analytics
1360
1383
1361
    {    # codeblock to limit scope of $module->mock
1384
    {    # codeblock to limit scope of $module->mock
Lines 2863-2869 subtest 'store() tests' => sub { Link Here
2863
            {
2886
            {
2864
                borrowernumber    => $patron->id,
2887
                borrowernumber    => $patron->id,
2865
                date              => '1970-01-01 14:00:01',
2888
                date              => '1970-01-01 14:00:01',
2866
                amountoutstanding => 0,
2889
                amountoutstanding =>  0,
2867
                amount            => -5,
2890
                amount            => -5,
2868
                interface         => 'commandline',
2891
                interface         => 'commandline',
2869
                credit_type_code  => 'PAYMENT'
2892
                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