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

(-)a/Koha/Biblio.pm (-18 / +25 lines)
Lines 296-319 sub check_booking { Link Here
296
296
297
    my $dtf               = Koha::Database->new->schema->storage->datetime_parser;
297
    my $dtf               = Koha::Database->new->schema->storage->datetime_parser;
298
    my $existing_bookings = $self->bookings(
298
    my $existing_bookings = $self->bookings(
299
        [
299
        {
300
            start_date => {
300
            '-and' => [
301
                '-between' => [
301
                {
302
                    $dtf->format_datetime($start_date),
302
                    '-or' => [
303
                    $dtf->format_datetime($end_date)
303
                        start_date => {
304
                ]
304
                            '-between' => [
305
            },
305
                                $dtf->format_datetime($start_date),
306
            end_date => {
306
                                $dtf->format_datetime($end_date)
307
                '-between' => [
307
                            ]
308
                    $dtf->format_datetime($start_date),
308
                        },
309
                    $dtf->format_datetime($end_date)
309
                        end_date => {
310
                ]
310
                            '-between' => [
311
            },
311
                                $dtf->format_datetime($start_date),
312
            {
312
                                $dtf->format_datetime($end_date)
313
                start_date => { '<' => $dtf->format_datetime($start_date) },
313
                            ]
314
                end_date   => { '>' => $dtf->format_datetime($end_date) }
314
                        },
315
            }
315
                        {
316
        ]
316
                            start_date => { '<' => $dtf->format_datetime($start_date) },
317
                            end_date   => { '>' => $dtf->format_datetime($end_date) }
318
                        }
319
                    ]
320
                },
321
                { status => { '-not_in' => [ 'cancelled', 'completed' ] } }
322
            ]
323
        }
317
    );
324
    );
318
325
319
    my $booked_count =
326
    my $booked_count =
(-)a/Koha/Bookings.pm (-2 / +2 lines)
Lines 44-51 sub filter_by_active { Link Here
44
    my ($self) = @_;
44
    my ($self) = @_;
45
    return $self->search(
45
    return $self->search(
46
        {
46
        {
47
            end_date => { '>='  => \'NOW()' },
47
            end_date => { '>='      => \'NOW()' },
48
            status   => { q{!=} => [ -and => qw(cancelled completed) ] }
48
            status   => { '-not_in' => [ 'cancelled', 'completed' ] }
49
        }
49
        }
50
    );
50
    );
51
}
51
}
(-)a/Koha/Item.pm (-18 / +25 lines)
Lines 702-725 sub check_booking { Link Here
702
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
702
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
703
703
704
    my $existing_bookings = $self->bookings(
704
    my $existing_bookings = $self->bookings(
705
        [
705
        {
706
            start_date => {
706
            '-and' => [
707
                '-between' => [
707
                {
708
                    $dtf->format_datetime($start_date),
708
                    '-or' => [
709
                    $dtf->format_datetime($end_date)
709
                        start_date => {
710
                ]
710
                            '-between' => [
711
            },
711
                                $dtf->format_datetime($start_date),
712
            end_date => {
712
                                $dtf->format_datetime($end_date)
713
                '-between' => [
713
                            ]
714
                    $dtf->format_datetime($start_date),
714
                        },
715
                    $dtf->format_datetime($end_date)
715
                        end_date => {
716
                ]
716
                            '-between' => [
717
            },
717
                                $dtf->format_datetime($start_date),
718
            {
718
                                $dtf->format_datetime($end_date)
719
                start_date => { '<' => $dtf->format_datetime($start_date) },
719
                            ]
720
                end_date   => { '>' => $dtf->format_datetime($end_date) }
720
                        },
721
            }
721
                        {
722
        ]
722
                            start_date => { '<' => $dtf->format_datetime($start_date) },
723
                            end_date   => { '>' => $dtf->format_datetime($end_date) }
724
                        }
725
                    ]
726
                },
727
                { status => { '-not_in' => [ 'cancelled', 'completed' ] } }
728
            ]
729
        }
723
    );
730
    );
724
731
725
    my $bookings_count =
732
    my $bookings_count =
(-)a/t/db_dependent/Koha/Biblio.t (-1 / +15 lines)
Lines 1851-1857 sub host_record { Link Here
1851
}
1851
}
1852
1852
1853
subtest 'check_booking tests' => sub {
1853
subtest 'check_booking tests' => sub {
1854
    plan tests => 4;
1854
    plan tests => 5;
1855
1855
1856
    $schema->storage->txn_begin;
1856
    $schema->storage->txn_begin;
1857
1857
Lines 1952-1956 subtest 'check_booking tests' => sub { Link Here
1952
        "Koha::Biblio->check_booking returns true if we pass the booking_id of one of the bookings that we would conflict with"
1952
        "Koha::Biblio->check_booking returns true if we pass the booking_id of one of the bookings that we would conflict with"
1953
    );
1953
    );
1954
1954
1955
    # Cancelled booking
1956
    $current_bookings[0]->update( { status => 'cancelled' } );
1957
    $can_book = $biblio->check_booking(
1958
        {
1959
            start_date => dt_from_string(),
1960
            end_date   => dt_from_string()->add( days => 7 ),
1961
        }
1962
    );
1963
    is(
1964
        $can_book,
1965
        1,
1966
        "Koha::Item->check_booking takes account of cancelled status in bookings check"
1967
    );
1968
1955
    $schema->storage->txn_rollback;
1969
    $schema->storage->txn_rollback;
1956
};
1970
};
(-)a/t/db_dependent/Koha/Item.t (-2 / +15 lines)
Lines 3006-3012 subtest 'find_booking' => sub { Link Here
3006
};
3006
};
3007
3007
3008
subtest 'check_booking tests' => sub {
3008
subtest 'check_booking tests' => sub {
3009
    plan tests => 5;
3009
    plan tests => 6;
3010
3010
3011
    $schema->storage->txn_begin;
3011
    $schema->storage->txn_begin;
3012
3012
Lines 3095-3100 subtest 'check_booking tests' => sub { Link Here
3095
        "Koha::Item->check_booking returns true if we pass the booking_id that would conflict"
3095
        "Koha::Item->check_booking returns true if we pass the booking_id that would conflict"
3096
    );
3096
    );
3097
3097
3098
    # Cancelled booking
3099
    $booking2->update( { status => 'cancelled' } );
3100
    $can_book = $item->check_booking(
3101
        {
3102
            start_date => dt_from_string(),
3103
            end_date   => dt_from_string()->add( days => 7 ),
3104
        }
3105
    );
3106
    is(
3107
        $can_book,
3108
        1,
3109
        "Koha::Item->check_booking returns true if the conflicting booking is cancelled"
3110
    );
3111
3098
    $booking2->delete();
3112
    $booking2->delete();
3099
3113
3100
    # Future booking
3114
    # Future booking
3101
- 

Return to bug 38175