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

(-)a/C4/Circulation.pm (-12 / +18 lines)
Lines 1251-1281 sub CanBookBeIssued { Link Here
1251
                patron_id     => $patron->borrowernumber
1251
                patron_id     => $patron->borrowernumber
1252
            }
1252
            }
1253
        )
1253
        )
1254
        )
1254
      )
1255
    {
1255
    {
1256
        my $booking_start = dt_from_string( $booking->start_date );
1257
1256
        # Booked to this patron :)
1258
        # Booked to this patron :)
1257
        if ( $booking->patron_id == $patron->borrowernumber ) {
1259
        if ( $booking->patron_id == $patron->borrowernumber ) {
1258
            if ( $now < dt_from_string( $booking->start_date ) ) {
1260
            if ( $now < $booking_start ) {
1259
                $needsconfirmation{'BOOKED_EARLY'} = $booking;
1261
                $needsconfirmation{'BOOKED_EARLY'} = $booking;
1260
            } else {
1262
            }
1263
            else {
1261
                $alerts{'BOOKED'} = $booking;
1264
                $alerts{'BOOKED'} = $booking;
1262
            }
1265
            }
1263
        }
1266
        }
1264
1267
1265
        # Booking starts before due date, reduce loan?
1266
        elsif ( $duedate > dt_from_string( $booking->start_date ) ) {
1267
            $needsconfirmation{'BOOKED_TO_ANOTHER'} = $booking;
1268
        }
1269
1270
        # Loan falls inside booking
1271
        else {
1268
        else {
1272
            $issuingimpossible{'BOOKED_TO_ANOTHER'} = $booking;
1269
            # Loan falls inside booking
1270
            if ( $now > $booking_start ) {
1271
                $issuingimpossible{'BOOKED_TO_ANOTHER'} = $booking;
1272
            }
1273
1274
            # Booking starts before due date, reduce loan?
1275
            else {
1276
                $needsconfirmation{'BOOKED_TO_ANOTHER'} = $booking;
1277
            }
1273
        }
1278
        }
1274
    }
1279
    }
1275
1280
1276
    ## CHECK AGE RESTRICTION
1281
    ## CHECK AGE RESTRICTION
1277
    my $agerestriction  = $biblioitem->agerestriction;
1282
    my $agerestriction = $biblioitem->agerestriction;
1278
    my ($restriction_age, $daysToAgeRestriction) = GetAgeRestriction( $agerestriction, $patron->unblessed );
1283
    my ( $restriction_age, $daysToAgeRestriction ) =
1284
      GetAgeRestriction( $agerestriction, $patron->unblessed );
1279
    if ( $daysToAgeRestriction && $daysToAgeRestriction > 0 ) {
1285
    if ( $daysToAgeRestriction && $daysToAgeRestriction > 0 ) {
1280
        if ( C4::Context->preference('AgeRestrictionOverride') ) {
1286
        if ( C4::Context->preference('AgeRestrictionOverride') ) {
1281
            $needsconfirmation{AGE_RESTRICTION} = "$agerestriction";
1287
            $needsconfirmation{AGE_RESTRICTION} = "$agerestriction";
(-)a/t/db_dependent/Circulation.t (-2 / +65 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 ) =
4611
      CanBookBeIssued( $patron2, $item->barcode,
4612
        dt_from_string()->add( days => 5 ),
4613
        undef, undef, undef );
4614
    is(
4615
        $issuingimpossible->{BOOKED_TO_ANOTHER}->booking_id,
4616
        $booking->booking_id,
4617
        "Another patron has booked this item with a start date before the proposed due date"
4618
    );
4619
4620
    ( $issuingimpossible, $needsconfirmation, $alerts, $messages ) =
4621
      CanBookBeIssued( $patron1, $item->barcode,
4622
        dt_from_string()->add( days => 5 ),
4623
        undef, undef, undef );
4624
    is( $alerts->{BOOKED}->booking_id,
4625
        $booking->booking_id, "Booked to this user" );
4626
4627
    # Booking start will clash before issue due
4628
    $booking->start_date( dt_from_string()->add( days => 3 ) )->store();
4629
4630
    ( $issuingimpossible, $needsconfirmation, $alerts, $messages ) =
4631
      CanBookBeIssued( $patron2, $item->barcode,
4632
        dt_from_string()->add( days => 5 ),
4633
        undef, undef, undef );
4634
    is(
4635
        $needsconfirmation->{BOOKED_TO_ANOTHER}->booking_id,
4636
        $booking->booking_id,
4637
"Another patron has booked this item for a period starting before the proposed due date"
4638
    );
4639
4640
    ( $issuingimpossible, $needsconfirmation, $alerts, $messages ) =
4641
      CanBookBeIssued( $patron1, $item->barcode,
4642
        dt_from_string()->add( days => 5 ),
4643
        undef, undef, undef );
4644
    is( $needsconfirmation->{BOOKED_EARLY}->booking_id,
4645
        $booking->booking_id,
4646
        "Booked to this user, but they're collecting early" );
4647
4648
    $schema->storage->txn_rollback;
4649
};
4650
4587
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
4651
subtest 'AddReturn should clear items.onloan for unissued items' => sub {
4588
    plan tests => 1;
4652
    plan tests => 1;
4589
4653
4590
- 

Return to bug 35248