Bug 41298: Fix filtering items by in transit

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 <anneli.osterman@koha-suomi.fi>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 0485296221)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-11-25 14:04:56 +01:00 committed by Paul Derscheid
parent eb6241644a
commit 01d8c0f1ed
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 45 additions and 18 deletions

View File

@ -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') ], },
{

View File

@ -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;
};