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

(-)a/Koha/Hold.pm (-2 / +2 lines)
Lines 783-795 sub is_suspended { Link Here
783
    return $self->suspend();
783
    return $self->suspend();
784
}
784
}
785
785
786
=head3 item_level_holds
786
=head3 item_level_holds_count
787
787
788
Returns the number (count) of item-level holds for this hold's biblionumber and patron
788
Returns the number (count) of item-level holds for this hold's biblionumber and patron
789
789
790
=cut
790
=cut
791
791
792
sub item_level_holds {
792
sub item_level_holds_count {
793
    my ($self) = @_;
793
    my ($self) = @_;
794
794
795
    return Koha::Holds->search(
795
    return Koha::Holds->search(
(-)a/api/v1/swagger/definitions/hold.yaml (-2 / +2 lines)
Lines 114-121 properties: Link Here
114
  item_level:
114
  item_level:
115
    type: boolean
115
    type: boolean
116
    description: If the hold is placed at item level
116
    description: If the hold is placed at item level
117
  item_level_holds:
117
  item_level_holds_count:
118
    type: 
118
    type:
119
      - integer
119
      - integer
120
      - "null"
120
      - "null"
121
    description: Count of item level holds for this bibliographic record
121
    description: Count of item level holds for this bibliographic record
(-)a/api/v1/swagger/paths/holds.yaml (-1 / +1 lines)
Lines 109-115 Link Here
109
            - item
109
            - item
110
            - patron
110
            - patron
111
            - item_group
111
            - item_group
112
            - item_level_holds
112
            - item_level_holds_count
113
        collectionFormat: csv
113
        collectionFormat: csv
114
    produces:
114
    produces:
115
      - application/json
115
      - application/json
(-)a/koha-tmpl/intranet-tmpl/prog/js/holds.js (-4 / +4 lines)
Lines 1314-1320 async function load_patron_holds_table(biblio_id, split_data) { Link Here
1314
            ajax: {
1314
            ajax: {
1315
                url: url,
1315
                url: url,
1316
            },
1316
            },
1317
            embed: ["patron", "item", "item_group", "item_level_holds"],
1317
            embed: ["patron", "item", "item_group", "item_level_holds_count"],
1318
            columnDefs: [
1318
            columnDefs: [
1319
                {
1319
                {
1320
                    targets: [2, 3],
1320
                    targets: [2, 3],
Lines 1347-1353 async function load_patron_holds_table(biblio_id, split_data) { Link Here
1347
                            '" data-hold-group-id="' +
1347
                            '" data-hold-group-id="' +
1348
                            row.hold_group_id +
1348
                            row.hold_group_id +
1349
                            '" data-item_level_hold="' +
1349
                            '" data-item_level_hold="' +
1350
                            row.item_level_holds +
1350
                            row.item_level_holds_count +
1351
                            '" data-waiting="' +
1351
                            '" data-waiting="' +
1352
                            (row.status === "W" ? "1" : "") +
1352
                            (row.status === "W" ? "1" : "") +
1353
                            '" data-intransit="' +
1353
                            '" data-intransit="' +
Lines 1641-1652 async function load_patron_holds_table(biblio_id, split_data) { Link Here
1641
                        }
1641
                        }
1642
1642
1643
                        // Handle item level holds
1643
                        // Handle item level holds
1644
                        if (row.item_level_holds) {
1644
                        if (row.item_level_holds_count) {
1645
                            const barcode =
1645
                            const barcode =
1646
                                row.item.external_id || __("No barcode");
1646
                                row.item.external_id || __("No barcode");
1647
                            const itemLink = `<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=${row.biblio_id}&itemnumber=${row.item_id}">${barcode.escapeHtml ? barcode.escapeHtml() : barcode}</a>`;
1647
                            const itemLink = `<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=${row.biblio_id}&itemnumber=${row.item_id}">${barcode.escapeHtml ? barcode.escapeHtml() : barcode}</a>`;
1648
1648
1649
                            if (row.item_level_holds >= 2) {
1649
                            if (row.item_level_holds_count >= 2) {
1650
                                return `${__("Only item")} ${itemLink}${group_hold_message}`;
1650
                                return `${__("Only item")} ${itemLink}${group_hold_message}`;
1651
                            }
1651
                            }
1652
1652
(-)a/t/db_dependent/Koha/Holds.t (-6 / +79 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 14;
23
use Test::More tests => 15;
24
use Test::Warn;
24
use Test::Warn;
25
25
26
use C4::Circulation qw( AddIssue );
26
use C4::Circulation qw( AddIssue );
Lines 466-473 subtest 'cancel' => sub { Link Here
466
        my $reserve_id = C4::Reserves::AddReserve($hold_info);
466
        my $reserve_id = C4::Reserves::AddReserve($hold_info);
467
        Koha::Holds->find($reserve_id)->cancel;
467
        Koha::Holds->find($reserve_id)->cancel;
468
        my $number_of_logs =
468
        my $number_of_logs =
469
            $schema->resultset('ActionLog')
469
            $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )
470
            ->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )
471
            ->count;
470
            ->count;
472
        is( $number_of_logs, 0, 'Without HoldsLog, Koha::Hold->cancel should not have logged' );
471
        is( $number_of_logs, 0, 'Without HoldsLog, Koha::Hold->cancel should not have logged' );
473
472
Lines 475-482 subtest 'cancel' => sub { Link Here
475
        $reserve_id = C4::Reserves::AddReserve($hold_info);
474
        $reserve_id = C4::Reserves::AddReserve($hold_info);
476
        Koha::Holds->find($reserve_id)->cancel;
475
        Koha::Holds->find($reserve_id)->cancel;
477
        $number_of_logs =
476
        $number_of_logs =
478
            $schema->resultset('ActionLog')
477
            $schema->resultset('ActionLog')->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )
479
            ->search( { module => 'HOLDS', action => 'CANCEL', object => $reserve_id } )
480
            ->count;
478
            ->count;
481
        is( $number_of_logs, 1, 'With HoldsLog, Koha::Hold->cancel should have logged' );
479
        is( $number_of_logs, 1, 'With HoldsLog, Koha::Hold->cancel should have logged' );
482
    };
480
    };
Lines 1296-1298 subtest 'processing() tests' => sub { Link Here
1296
1294
1297
    $schema->storage->txn_rollback;
1295
    $schema->storage->txn_rollback;
1298
};
1296
};
1299
- 
1297
1298
subtest 'item_level_holds_count() tests' => sub {
1299
    plan tests => 6;
1300
1301
    $schema->storage->txn_begin;
1302
1303
    my $biblio       = $builder->build_sample_biblio;
1304
    my $item_1       = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
1305
    my $item_2       = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
1306
    my $patron       = $builder->build_object( { class => 'Koha::Patrons' } );
1307
    my $other_patron = $builder->build_object( { class => 'Koha::Patrons' } );
1308
1309
    # Create a biblio-level hold for the patron
1310
    my $biblio_hold = $builder->build_object(
1311
        {
1312
            class => 'Koha::Holds',
1313
            value => {
1314
                borrowernumber  => $patron->borrowernumber,
1315
                biblionumber    => $biblio->biblionumber,
1316
                itemnumber      => undef,
1317
                item_level_hold => 0,
1318
            }
1319
        }
1320
    );
1321
1322
    is( $biblio_hold->item_level_holds_count, 0, 'No item-level holds yet for this patron/biblio' );
1323
1324
    # Create first item-level hold for the patron
1325
    my $item_hold_1 = $builder->build_object(
1326
        {
1327
            class => 'Koha::Holds',
1328
            value => {
1329
                borrowernumber  => $patron->borrowernumber,
1330
                biblionumber    => $biblio->biblionumber,
1331
                itemnumber      => $item_1->itemnumber,
1332
                item_level_hold => 1,
1333
            }
1334
        }
1335
    );
1336
1337
    is( $item_hold_1->item_level_holds_count, 1, 'One item-level hold for this patron/biblio' );
1338
    is( $biblio_hold->item_level_holds_count, 1, 'Biblio-level hold also sees the item-level hold count' );
1339
1340
    # Create second item-level hold for the patron
1341
    my $item_hold_2 = $builder->build_object(
1342
        {
1343
            class => 'Koha::Holds',
1344
            value => {
1345
                borrowernumber  => $patron->borrowernumber,
1346
                biblionumber    => $biblio->biblionumber,
1347
                itemnumber      => $item_2->itemnumber,
1348
                item_level_hold => 1,
1349
            }
1350
        }
1351
    );
1352
1353
    is( $item_hold_2->item_level_holds_count, 2, 'Two item-level holds for this patron/biblio' );
1354
1355
    # Create item-level hold for different patron - should not be counted
1356
    my $other_patron_hold = $builder->build_object(
1357
        {
1358
            class => 'Koha::Holds',
1359
            value => {
1360
                borrowernumber  => $other_patron->borrowernumber,
1361
                biblionumber    => $biblio->biblionumber,
1362
                itemnumber      => $item_1->itemnumber,
1363
                item_level_hold => 1,
1364
            }
1365
        }
1366
    );
1367
1368
    is( $item_hold_1->item_level_holds_count,       2, 'Still two item-level holds for original patron' );
1369
    is( $other_patron_hold->item_level_holds_count, 1, 'Only one item-level hold for other patron' );
1370
1371
    $schema->storage->txn_rollback;
1372
};

Return to bug 23269