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

(-)a/Koha/Item.pm (-25 / +34 lines)
Lines 605-613 implementation. Link Here
605
sub find_booking {
605
sub find_booking {
606
    my ( $self, $params ) = @_;
606
    my ( $self, $params ) = @_;
607
607
608
    my $checkout_date = $params->{checkout_date};
608
    my $start_date = $params->{checkout_date};
609
    my $due_date      = $params->{due_date};
609
    my $end_date   = $params->{due_date};
610
    my $biblio        = $self->biblio;
610
    my $biblio     = $self->biblio;
611
611
612
    my $rule = Koha::CirculationRules->get_effective_rule(
612
    my $rule = Koha::CirculationRules->get_effective_rule(
613
        {
613
        {
Lines 617-649 sub find_booking { Link Here
617
        }
617
        }
618
    );
618
    );
619
    my $preparation_period = $rule ? $rule->rule_value : 0;
619
    my $preparation_period = $rule ? $rule->rule_value : 0;
620
    $due_date = $due_date->clone->add( days => $preparation_period );
620
    $end_date = $end_date->clone->add( days => $preparation_period );
621
621
622
    my $dtf      = Koha::Database->new->schema->storage->datetime_parser;
622
    my $dtf      = Koha::Database->new->schema->storage->datetime_parser;
623
    my $bookings = $biblio->bookings(
623
    my $bookings = $biblio->bookings(
624
        [
624
        {
625
            # Proposed checkout starts during booked period
625
            '-and' => [
626
            start_date => {
626
                {
627
                '-between' => [
627
                    '-or' => [
628
                    $dtf->format_datetime($checkout_date),
629
                    $dtf->format_datetime($due_date)
630
                ]
631
            },
632
628
633
            # Proposed checkout is due during booked period
629
                        # Proposed checkout starts during booked period
634
            end_date => {
630
                        start_date => {
635
                '-between' => [
631
                            '-between' => [
636
                    $dtf->format_datetime($checkout_date),
632
                                $dtf->format_datetime($start_date),
637
                    $dtf->format_datetime($due_date)
633
                                $dtf->format_datetime($end_date)
638
                ]
634
                            ]
639
            },
635
                        },
640
636
641
            # Proposed checkout would contain the booked period
637
                        # Proposed checkout is due during booked period
642
            {
638
                        end_date => {
643
                start_date => { '<' => $dtf->format_datetime($checkout_date) },
639
                            '-between' => [
644
                end_date   => { '>' => $dtf->format_datetime($due_date) }
640
                                $dtf->format_datetime($start_date),
645
            }
641
                                $dtf->format_datetime($end_date)
646
        ],
642
                            ]
643
                        },
644
645
                        # Proposed checkout would contain the booked period
646
                        {
647
                            start_date => { '<' => $dtf->format_datetime($start_date) },
648
                            end_date   => { '>' => $dtf->format_datetime($end_date) }
649
                        }
650
                    ]
651
                },
652
                { status => { '-not_in' => [ 'cancelled', 'completed' ] } }
653
            ]
654
        },
647
        { order_by => { '-asc' => 'start_date' } }
655
        { order_by => { '-asc' => 'start_date' } }
648
    );
656
    );
649
657
Lines 668-673 sub find_booking { Link Here
668
676
669
        # Booking for another item
677
        # Booking for another item
670
        elsif ( defined( $booking->item_id ) ) {
678
        elsif ( defined( $booking->item_id ) ) {
679
671
            # Due for another booking, remove from pool
680
            # Due for another booking, remove from pool
672
            delete $loanable_items->{ $booking->item_id };
681
            delete $loanable_items->{ $booking->item_id };
673
            next;
682
            next;
(-)a/t/db_dependent/Koha/Item.t (-2 / +16 lines)
Lines 2897-2903 subtest 'bookings' => sub { Link Here
2897
};
2897
};
2898
2898
2899
subtest 'find_booking' => sub {
2899
subtest 'find_booking' => sub {
2900
    plan tests => 7;
2900
    plan tests => 8;
2901
2901
2902
    $schema->storage->txn_begin;
2902
    $schema->storage->txn_begin;
2903
2903
Lines 3004-3009 subtest 'find_booking' => sub { Link Here
3004
        "Koha::Item->find_booking returns the current booking not a future one"
3004
        "Koha::Item->find_booking returns the current booking not a future one"
3005
    );
3005
    );
3006
3006
3007
    # Cancelled booking
3008
    $booking2->status('cancelled')->store();
3009
    $found_booking = $item->find_booking(
3010
        {
3011
            checkout_date => dt_from_string(),
3012
            due_date      => dt_from_string()->add( days => 7 ),
3013
        }
3014
    );
3015
3016
    is(
3017
        $found_booking,
3018
        undef,
3019
        "Koha::Item->find_booking returns undefined when the current booking is cancelled and the future booking is out of range"
3020
    );
3021
3007
    subtest "Preparation period handling" => sub {
3022
    subtest "Preparation period handling" => sub {
3008
        plan tests => 3;
3023
        plan tests => 3;
3009
3024
3010
- 

Return to bug 38175