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

(-)a/Koha/Biblio.pm (-2 / +9 lines)
Lines 394-403 sub check_booking { Link Here
394
        ? $existing_bookings->search( { booking_id => { '!=' => $booking_id } } )->count
394
        ? $existing_bookings->search( { booking_id => { '!=' => $booking_id } } )->count
395
        : $existing_bookings->count;
395
        : $existing_bookings->count;
396
396
397
    # Only count checkouts on bookable items; checkouts on non-bookable
398
    # sibling items should not reduce the pool of available bookable items.
399
    my $bookable_item_ids = [ $bookable_items->reset->get_column('itemnumber') ];
400
397
    my $checkouts = $self->current_checkouts->search(
401
    my $checkouts = $self->current_checkouts->search(
398
        {
402
        {
399
            date_due        => { '>='      => $dtf->format_datetime($start_date) },
403
            date_due        => { '>=' => $dtf->format_datetime($start_date) },
400
            "me.itemnumber" => { '-not_in' => $existing_bookings->_resultset->get_column('item_id')->as_query }
404
            "me.itemnumber" => {
405
                '-not_in' => $existing_bookings->_resultset->get_column('item_id')->as_query,
406
                '-in'     => $bookable_item_ids,
407
            },
401
        }
408
        }
402
    );
409
    );
403
    $booked_count += $checkouts->count;
410
    $booked_count += $checkouts->count;
(-)a/t/db_dependent/Koha/Biblio.t (-2 / +44 lines)
Lines 2214-2220 sub host_record { Link Here
2214
}
2214
}
2215
2215
2216
subtest 'check_booking tests' => sub {
2216
subtest 'check_booking tests' => sub {
2217
    plan tests => 6;
2217
    plan tests => 7;
2218
2218
2219
    $schema->storage->txn_begin;
2219
    $schema->storage->txn_begin;
2220
2220
Lines 2396-2400 subtest 'check_booking tests' => sub { Link Here
2396
2396
2397
    is( $check_booking, 1, "Koha::Biblio->check_booking returns true when we can book on an item" );
2397
    is( $check_booking, 1, "Koha::Biblio->check_booking returns true when we can book on an item" );
2398
2398
2399
    subtest 'checkouts on non-bookable items do not cause false clashes' => sub {
2400
        plan tests => 2;
2401
2402
        my $nb_biblio     = $builder->build_sample_biblio();
2403
        my $bookable_item = $builder->build_sample_item( { biblionumber => $nb_biblio->biblionumber, bookable => 1 } );
2404
        my $non_bookable_item =
2405
            $builder->build_sample_item( { biblionumber => $nb_biblio->biblionumber, bookable => 0 } );
2406
2407
        my $nb_patron = $builder->build_object( { class => 'Koha::Patrons' } );
2408
2409
        # Check out the non-bookable item
2410
        AddIssue( $nb_patron, $non_bookable_item->barcode );
2411
2412
        my $nb_start = dt_from_string()->truncate( to => 'day' );
2413
        my $nb_end   = $nb_start->clone->add( days => 7 );
2414
2415
        my $can_book = $nb_biblio->check_booking(
2416
            {
2417
                start_date => $nb_start,
2418
                end_date   => $nb_end,
2419
            }
2420
        );
2421
        is(
2422
            $can_book, 1,
2423
            "Checkout on non-bookable item does not reduce availability"
2424
        );
2425
2426
        # Now also check out the bookable item to confirm it
2427
        # correctly detects unavailability
2428
        AddIssue( $nb_patron, $bookable_item->barcode );
2429
2430
        $can_book = $nb_biblio->check_booking(
2431
            {
2432
                start_date => $nb_start,
2433
                end_date   => $nb_end,
2434
            }
2435
        );
2436
        is(
2437
            $can_book, 0,
2438
            "Checkout on bookable item correctly reduces availability"
2439
        );
2440
    };
2441
2399
    $schema->storage->txn_rollback;
2442
    $schema->storage->txn_rollback;
2400
};
2443
};
2401
- 

Return to bug 41886