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

(-)a/C4/Circulation.pm (-16 / +17 lines)
Lines 1245-1281 sub CanBookBeIssued { Link Here
1245
    ## CHECK FOR BOOKINGS
1245
    ## CHECK FOR BOOKINGS
1246
    if (
1246
    if (
1247
        my $booking = $item_object->find_booking(
1247
        my $booking = $item_object->find_booking(
1248
            {
1248
            { checkout_date => $now, due_date => $duedate, patron_id => $patron->borrowernumber }
1249
                checkout_date => $now,
1250
                due_date      => $duedate,
1251
                patron_id     => $patron->borrowernumber
1252
            }
1253
        )
1249
        )
1254
        )
1250
        )
1255
    {
1251
    {
1252
        my $booking_start = dt_from_string( $booking->start_date );
1253
1256
        # Booked to this patron :)
1254
        # Booked to this patron :)
1257
        if ( $booking->patron_id == $patron->borrowernumber ) {
1255
        if ( $booking->patron_id == $patron->borrowernumber ) {
1258
            if ( $now < dt_from_string( $booking->start_date ) ) {
1256
            if ( $now < $booking_start ) {
1259
                $needsconfirmation{'BOOKED_EARLY'} = $booking;
1257
                $needsconfirmation{'BOOKED_EARLY'} = $booking;
1260
            } else {
1258
            } else {
1261
                $alerts{'BOOKED'} = $booking;
1259
                $alerts{'BOOKED'} = $booking;
1262
            }
1260
            }
1263
        }
1264
1261
1265
        # Booking starts before due date, reduce loan?
1262
        } else {
1266
        elsif ( $duedate > dt_from_string( $booking->start_date ) ) {
1267
            $needsconfirmation{'BOOKED_TO_ANOTHER'} = $booking;
1268
        }
1269
1263
1270
        # Loan falls inside booking
1264
            # Loan falls inside booking
1271
        else {
1265
            if ( $now > $booking_start ) {
1272
            $issuingimpossible{'BOOKED_TO_ANOTHER'} = $booking;
1266
                $issuingimpossible{'BOOKED_TO_ANOTHER'} = $booking;
1267
            }
1268
1269
            # Booking starts before due date, reduce loan?
1270
            else {
1271
                $needsconfirmation{'BOOKED_TO_ANOTHER'} = $booking;
1272
            }
1273
        }
1273
        }
1274
    }
1274
    }
1275
1275
1276
    ## CHECK AGE RESTRICTION
1276
    ## CHECK AGE RESTRICTION
1277
    my $agerestriction  = $biblioitem->agerestriction;
1277
    my $agerestriction = $biblioitem->agerestriction;
1278
    my ($restriction_age, $daysToAgeRestriction) = GetAgeRestriction( $agerestriction, $patron->unblessed );
1278
    my ( $restriction_age, $daysToAgeRestriction ) =
1279
      GetAgeRestriction( $agerestriction, $patron->unblessed );
1279
    if ( $daysToAgeRestriction && $daysToAgeRestriction > 0 ) {
1280
    if ( $daysToAgeRestriction && $daysToAgeRestriction > 0 ) {
1280
        if ( C4::Context->preference('AgeRestrictionOverride') ) {
1281
        if ( C4::Context->preference('AgeRestrictionOverride') ) {
1281
            $needsconfirmation{AGE_RESTRICTION} = "$agerestriction";
1282
            $needsconfirmation{AGE_RESTRICTION} = "$agerestriction";
(-)a/t/db_dependent/Circulation.t (-2 / +73 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 68;
21
use Test::More tests => 69;
22
use Test::Exception;
22
use Test::Exception;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Deep qw( cmp_deeply );
24
use Test::Deep qw( cmp_deeply );
Lines 42-47 use C4::Overdues qw( CalcFine UpdateFine get_chargeable_units ); Link Here
42
use C4::Members::Messaging qw( SetMessagingPreference );
42
use C4::Members::Messaging qw( SetMessagingPreference );
43
use Koha::DateUtils qw( dt_from_string output_pref );
43
use Koha::DateUtils qw( dt_from_string output_pref );
44
use Koha::Database;
44
use Koha::Database;
45
use Koha::Bookings;
45
use Koha::Items;
46
use Koha::Items;
46
use Koha::Item::Transfers;
47
use Koha::Item::Transfers;
47
use Koha::Checkouts;
48
use Koha::Checkouts;
Lines 4584-4589 subtest 'CanBookBeIssued | recalls' => sub { Link Here
4584
    $recall->set_cancelled;
4585
    $recall->set_cancelled;
4585
};
4586
};
4586
4587
4588
subtest 'CanBookBeIssued | bookings' => sub {
4589
    plan tests => 4;
4590
4591
    my $schema = Koha::Database->schema;
4592
    $schema->storage->txn_begin;
4593
4594
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } );
4595
    my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } );
4596
    my $item    = $builder->build_sample_item( { bookable => 1 } );
4597
4598
    # item-level booking
4599
    my $booking = Koha::Booking->new(
4600
        {
4601
            patron_id  => $patron1->borrowernumber,
4602
            item_id    => $item->itemnumber,
4603
            biblio_id  => $item->biblio->biblionumber,
4604
            start_date => dt_from_string()->subtract( days => 1 ),
4605
            end_date   => dt_from_string()->add( days => 6 ),
4606
        }
4607
    )->store();
4608
4609
    # Booking encompasses proposed checkout
4610
    my ( $issuingimpossible, $needsconfirmation, $alerts, $messages ) = CanBookBeIssued(
4611
        $patron2, $item->barcode,
4612
        dt_from_string()->add( days => 5 ),
4613
        undef, undef, undef
4614
    );
4615
    is(
4616
        $issuingimpossible->{BOOKED_TO_ANOTHER}->booking_id,
4617
        $booking->booking_id,
4618
        "Another patron has booked this item with a start date before the proposed due date"
4619
    );
4620
4621
    ( $issuingimpossible, $needsconfirmation, $alerts, $messages ) = CanBookBeIssued(
4622
        $patron1, $item->barcode,
4623
        dt_from_string()->add( days => 5 ),
4624
        undef, undef, undef
4625
    );
4626
    is(
4627
        $alerts->{BOOKED}->booking_id,
4628
        $booking->booking_id, "Booked to this user"
4629
    );
4630
4631
    # Booking start will clash before issue due
4632
    $booking->start_date( dt_from_string()->add( days => 3 ) )->store();
4633
4634
    ( $issuingimpossible, $needsconfirmation, $alerts, $messages ) = CanBookBeIssued(
4635
        $patron2, $item->barcode,
4636
        dt_from_string()->add( days => 5 ),
4637
        undef, undef, undef
4638
    );
4639
    is(
4640
        $needsconfirmation->{BOOKED_TO_ANOTHER}->booking_id,
4641
        $booking->booking_id,
4642
        "Another patron has booked this item for a period starting before the proposed due date"
4643
    );
4644
4645
    ( $issuingimpossible, $needsconfirmation, $alerts, $messages ) = CanBookBeIssued(
4646
        $patron1, $item->barcode,
4647
        dt_from_string()->add( days => 5 ),
4648
        undef, undef, undef
4649
    );
4650
    is(
4651
        $needsconfirmation->{BOOKED_EARLY}->booking_id,
4652
        $booking->booking_id,
4653
        "Booked to this user, but they're collecting early"
4654
    );
4655
4656
    $schema->storage->txn_rollback;
4657
};
4658
4587
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
4659
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
4588
    plan tests => 1;
4660
    plan tests => 1;
4589
4661
4590
- 

Return to bug 35248