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

(-)a/t/db_dependent/Circulation.t (-1 / +125 lines)
Lines 6883-6888 subtest 'AddIssue records staff who checked out item if appropriate' => sub { Link Here
6883
    );
6883
    );
6884
};
6884
};
6885
6885
6886
subtest 'AddIssue | booking status handling' => sub {
6887
    plan tests => 5;
6888
6889
    my $schema = Koha::Database->schema;
6890
    $schema->storage->txn_begin;
6891
6892
    my $patron1        = $builder->build_object( { class => 'Koha::Patrons' } );
6893
    my $patron2        = $builder->build_object( { class => 'Koha::Patrons' } );
6894
    my $pickup_library = $builder->build_object( { class => 'Koha::Libraries' } );
6895
    my $item           = $builder->build_sample_item( { bookable => 1 } );
6896
6897
    # Test 1: Patron checks out item with their own booking - should mark as completed
6898
    my $booking1 = Koha::Booking->new(
6899
        {
6900
            patron_id         => $patron1->borrowernumber,
6901
            pickup_library_id => $pickup_library->branchcode,
6902
            item_id           => $item->itemnumber,
6903
            biblio_id         => $item->biblio->biblionumber,
6904
            start_date        => dt_from_string(),
6905
            end_date          => dt_from_string()->add( days => 7 ),
6906
        }
6907
    )->store();
6908
6909
    my $issue1 = AddIssue( $patron1, $item->barcode, dt_from_string()->add( days => 7 ) );
6910
    $booking1->discard_changes();
6911
6912
    is( $booking1->status, 'completed', "Patron's own booking marked as completed when item checked out" );
6913
6914
    # Clean up for next test
6915
    AddReturn( $item->barcode, $pickup_library->branchcode );
6916
    $booking1->delete();
6917
6918
    # Test 2: Another patron checks out item with different patron's booking overlapping actual booking period - should cancel booking
6919
    my $booking2 = Koha::Booking->new(
6920
        {
6921
            patron_id         => $patron1->borrowernumber,
6922
            pickup_library_id => $pickup_library->branchcode,
6923
            item_id           => $item->itemnumber,
6924
            biblio_id         => $item->biblio->biblionumber,
6925
            start_date        => dt_from_string()->add( days => 1 ),
6926
            end_date          => dt_from_string()->add( days => 5 ),
6927
        }
6928
    )->store();
6929
6930
    my $issue2 = AddIssue( $patron2, $item->barcode, dt_from_string()->add( days => 3 ) );
6931
    $booking2->discard_changes();
6932
6933
    is(
6934
        $booking2->status, 'cancelled',
6935
        "Another patron's booking cancelled when checkout overlaps actual booking period"
6936
    );
6937
6938
    # Clean up for next test
6939
    AddReturn( $item->barcode, $pickup_library->branchcode );
6940
    $booking2->delete();
6941
6942
    # Test 3: Another patron checks out item - checkout period only in lead period - should NOT cancel booking
6943
    # First set up a lead period rule
6944
    Koha::CirculationRules->set_rules(
6945
        {
6946
            branchcode => '*',
6947
            itemtype   => $item->effective_itemtype,
6948
            rules      => {
6949
                bookings_lead_period => 3,
6950
            },
6951
        }
6952
    );
6953
6954
    my $booking3 = Koha::Booking->new(
6955
        {
6956
            patron_id         => $patron1->borrowernumber,
6957
            pickup_library_id => $pickup_library->branchcode,
6958
            item_id           => $item->itemnumber,
6959
            biblio_id         => $item->biblio->biblionumber,
6960
            start_date        => dt_from_string()->add( days => 5 ),
6961
            end_date          => dt_from_string()->add( days => 10 ),
6962
        }
6963
    )->store();
6964
6965
    # Issue that would return before booking starts (only conflicts due to lead period)
6966
    my $issue3 = AddIssue( $patron2, $item->barcode, dt_from_string()->add( days => 4 ) );
6967
    $booking3->discard_changes();
6968
6969
    is(
6970
        $booking3->status, 'new',
6971
        "Another patron's booking NOT cancelled when checkout only conflicts with lead period"
6972
    );
6973
6974
    # Clean up for next test
6975
    AddReturn( $item->barcode, $pickup_library->branchcode );
6976
    $booking3->delete();
6977
6978
    # Test 4: Edge case - checkout period starts before booking and ends after booking (encompasses booking)
6979
    my $booking4 = Koha::Booking->new(
6980
        {
6981
            patron_id         => $patron1->borrowernumber,
6982
            pickup_library_id => $pickup_library->branchcode,
6983
            item_id           => $item->itemnumber,
6984
            biblio_id         => $item->biblio->biblionumber,
6985
            start_date        => dt_from_string()->add( days => 2 ),
6986
            end_date          => dt_from_string()->add( days => 4 ),
6987
        }
6988
    )->store();
6989
6990
    # Issue that encompasses the entire booking period
6991
    my $issue4 = AddIssue( $patron2, $item->barcode, dt_from_string()->add( days => 6 ) );
6992
    $booking4->discard_changes();
6993
6994
    is(
6995
        $booking4->status, 'cancelled',
6996
        "Another patron's booking cancelled when checkout encompasses entire booking period"
6997
    );
6998
6999
    # Clean up for next test
7000
    AddReturn( $item->barcode, $pickup_library->branchcode );
7001
    $booking4->delete();
7002
7003
    # Test 5: No booking found - should not cause errors
7004
    my $issue5 = AddIssue( $patron1, $item->barcode, dt_from_string()->add( days => 7 ) );
7005
7006
    ok( $issue5, "AddIssue works normally when no booking is found" );
7007
7008
    $schema->storage->txn_rollback;
7009
};
7010
6886
subtest "Item's onloan value should be set if checked out item is checked out to a different patron" => sub {
7011
subtest "Item's onloan value should be set if checked out item is checked out to a different patron" => sub {
6887
    plan tests => 2;
7012
    plan tests => 2;
6888
7013
6889
- 

Return to bug 40296