From 620d5b73af8d6ccb70b5a7a240c8e9f5049a73f7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 25 Nov 2025 14:04:56 +0100 Subject: [PATCH] Bug 41298: Fix filtering items by in transit MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 The filtering condition was not correct, the presence of a line in the transfer table is not enough to now if the item is in transit. Here we filter reusing the same conditions as Koha::Item::Transfer->in_transit Test plan: Have at least 2 items for a given bibliographic record Transfer item 1 Transfer item 2 Receive/Fullfill the transfer for item 1 Item 1 is now available and item 2 is in transit Go to items record and filter holdings table with status "In transit" => Only item 2 is displayed Filter holdings table with status "Available" => Only item 1 is displayed Signed-off-by: Anneli Österman Signed-off-by: Marcel de Rooy --- Koha/Items.pm | 4 +++ t/db_dependent/Koha/Items.t | 59 ++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Koha/Items.pm b/Koha/Items.pm index 830bfc3914..862631fbfb 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -260,6 +260,10 @@ sub filter_by_in_transit { my ( $self, $params ) = @_; $params //= {}; + $params->{datesent} = { '!=' => undef }; + $params->{datearrived} = undef; + $params->{datecancelled} = undef; + my $transfers = Koha::Item::Transfers->search( { %$params, 'me.itemnumber' => [ $self->get_column('itemnumber') ], }, { diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 29a29a50e3..3e74ac1fb6 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -155,10 +155,10 @@ subtest 'search' => sub { } ); - ok( $lost_items->count == 1, "Filtered to 1 lost item" ); - ok( $damaged_items->count == 1, "Filtered to 1 damaged item" ); - ok( $withdrawn_items->count == 1, "Filtered to 1 withdrawn item" ); - ok( $notforloan_items->count == 1, "Filtered to 1 notforloan item" ); + is( $lost_items->count, 1, "Filtered to 1 lost item" ); + is( $damaged_items->count, 1, "Filtered to 1 damaged item" ); + is( $withdrawn_items->count, 1, "Filtered to 1 withdrawn item" ); + is( $notforloan_items->count, 1, "Filtered to 1 notforloan item" ); C4::Circulation::AddIssue( $patron, $item_1->barcode ); @@ -169,15 +169,19 @@ subtest 'search' => sub { } ); - ok( $checked_out_items->count == 1, "Filtered to 1 checked out item" ); + is( $checked_out_items->count, 1, "Filtered to 1 checked out item" ); my $transfer_1 = $builder->build_object( { class => 'Koha::Item::Transfers', value => { - itemnumber => $item_2->itemnumber, - frombranch => $library_1->{branchcode}, - tobranch => $library_2->{branchcode}, + itemnumber => $item_2->itemnumber, + frombranch => $library_1->{branchcode}, + tobranch => $library_2->{branchcode}, + datesent => \'NOW()', + datearrived => undef, + datecancelled => undef, + daterequested => \'NOW()', } } ); @@ -189,7 +193,7 @@ subtest 'search' => sub { } ); - ok( $in_transit_items->count == 1, "Filtered to 1 in transit item" ); + is( $in_transit_items->count, 1, "Filtered to 1 in transit item" ); my $item_7 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, } ); @@ -209,7 +213,7 @@ subtest 'search' => sub { } ); - ok( $on_hold_items->count == 1, "Filtered to 1 on hold item" ); + is( $on_hold_items->count, 1, "Filtered to 1 on hold item" ); my $item_8 = $builder->build_sample_item( { @@ -225,7 +229,7 @@ subtest 'search' => sub { } ); - ok( $restricted_items->count == 1, "Filtered to 1 restricted item" ); + is( $restricted_items->count, 1, "Filtered to 1 restricted item" ); $schema->storage->txn_rollback; }; @@ -2616,7 +2620,7 @@ subtest 'filter_by_checked_out' => sub { }; subtest 'filter_by_in_transit' => sub { - plan tests => 3; + plan tests => 5; $schema->storage->txn_begin; @@ -2636,9 +2640,13 @@ subtest 'filter_by_in_transit' => sub { { class => 'Koha::Item::Transfers', value => { - itemnumber => $item_1->itemnumber, - frombranch => $library_1->{branchcode}, - tobranch => $library_2->{branchcode}, + itemnumber => $item_1->itemnumber, + frombranch => $library_1->{branchcode}, + tobranch => $library_2->{branchcode}, + datesent => \'NOW()', + datearrived => undef, + datecancelled => undef, + daterequested => \'NOW()', } } ); @@ -2649,15 +2657,30 @@ subtest 'filter_by_in_transit' => sub { { class => 'Koha::Item::Transfers', value => { - itemnumber => $item_2->itemnumber, - frombranch => $library_2->{branchcode}, - tobranch => $library_1->{branchcode}, + itemnumber => $item_2->itemnumber, + frombranch => $library_2->{branchcode}, + tobranch => $library_1->{branchcode}, + datesent => \'NOW()', + datearrived => undef, + datecancelled => undef, + daterequested => \'NOW()', } } ); is( $biblio->items->filter_by_in_transit->count, 2, "Filtered 2 in transit items" ); + $item_1->get_transfer->receive; + + is_deeply( + [ $biblio->items->filter_by_in_transit->get_column('itemnumber') ], [ $item_2->itemnumber ], + "First item has been received" + ); + + $item_2->get_transfer->cancel( { reason => "Manual", force => 1 } ); + + is( $biblio->items->filter_by_in_transit->count, 0, "Second item's transfer has been cancelled" ); + $schema->storage->txn_rollback; }; -- 2.39.5