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

(-)a/Koha/Item.pm (-1 / +3 lines)
Lines 586-592 sub bookings { Link Here
586
586
587
  my $booking = $item->find_booking( { checkout_date => $now, due_date => $future_date } );
587
  my $booking = $item->find_booking( { checkout_date => $now, due_date => $future_date } );
588
588
589
Find the first booking that would conflict with the passed checkout dates for this item.
589
Find the first booking that would conflict with the passed checkout dates for this item.  If a booking 
590
lead period is configured for the itemtype we will also take that into account here, counting bookings
591
that fall in that lead period as conflicts too.
590
592
591
FIXME: This can be simplified, it was originally intended to iterate all biblio level bookings
593
FIXME: This can be simplified, it was originally intended to iterate all biblio level bookings
592
to catch cases where this item may be the last available to satisfy a biblio level only booking.
594
to catch cases where this item may be the last available to satisfy a biblio level only booking.
(-)a/t/db_dependent/Koha/Item.t (-2 / +49 lines)
Lines 2600-2606 subtest 'bookings' => sub { Link Here
2600
};
2600
};
2601
2601
2602
subtest 'find_booking' => sub {
2602
subtest 'find_booking' => sub {
2603
    plan tests => 6;
2603
    plan tests => 7;
2604
2604
2605
    $schema->storage->txn_begin;
2605
    $schema->storage->txn_begin;
2606
2606
Lines 2707-2712 subtest 'find_booking' => sub { Link Here
2707
        "Koha::Item->find_booking returns the current booking not a future one"
2707
        "Koha::Item->find_booking returns the current booking not a future one"
2708
    );
2708
    );
2709
2709
2710
    subtest "Preparation period handling" => sub {
2711
        plan tests => 3;
2712
2713
        # Delete current booking, is the future booking returned?
2714
        $booking2->delete();
2715
        $found_booking = $item->find_booking(
2716
            {
2717
                checkout_date => dt_from_string(),
2718
                due_date      => dt_from_string()->add( days => 7 ),
2719
            }
2720
        );
2721
2722
        is(
2723
            $found_booking,
2724
            undef,
2725
            "Koha::Item->find_booking returns undefined when the current booking is deleted and the future booking is out of range and there's no lead period rule"
2726
        );
2727
2728
        # Adding lead period rule
2729
        Koha::CirculationRules->set_rules(
2730
            {
2731
                branchcode   => '*',
2732
                itemtype     => $item->effective_itemtype,
2733
                rules        => {
2734
                    bookings_lead_period => 3,
2735
                },
2736
            }
2737
        );
2738
2739
        $found_booking = $item->find_booking(
2740
            {
2741
                checkout_date => dt_from_string(),
2742
                due_date      => dt_from_string()->add( days => 7 ),
2743
            }
2744
        );
2745
2746
        is(
2747
            ref($found_booking),
2748
            'Koha::Booking',
2749
            "Koha::Item->find_booking returns a Koha::Booking if one exists that would clash with the passed dates including lead period"
2750
        );
2751
        is(
2752
            $found_booking->booking_id, $booking3->booking_id,
2753
            "Koha::Item->find_booking returns the future booking when lead period is included"
2754
        );
2755
2756
    };
2757
2710
    $schema->storage->txn_rollback;
2758
    $schema->storage->txn_rollback;
2711
};
2759
};
2712
2760
2713
- 

Return to bug 34440