From edc5ec9fb3b0469bb89f33f3e845094f289eb5c1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 5 Jan 2024 16:08:44 +0000 Subject: [PATCH] Bug 35100: Various fixes 1) Don't automagically always set a transfer to in transit on checkin.. wait for the user to actually confirm that's the case 2) New transfers triggered by a hold should take precidence, so hide transfers for any other reason from display 3) Update get_transfer and get_transfers to ensure ordering isn't lost when prefetch is used and add tests for this Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Circulation.pm | 12 +- C4/Items.pm | 2 +- Koha/Item.pm | 15 +- Koha/Schema/Result/Item.pm | 3 +- circ/returns.pl | 12 +- .../prog/en/modules/circ/returns.tt | 5 +- t/db_dependent/Circulation.t | 35 ++- t/db_dependent/Koha/Item.t | 251 +++++++++++++++++- t/db_dependent/Koha/Items.t | 78 +----- 9 files changed, 304 insertions(+), 109 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index b454ff241f8..ee024c45928 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2364,10 +2364,9 @@ sub AddReturn { else { $messages->{'TransferTrigger'} = $transfer->reason; if ( $transfer->frombranch eq $branch ) { - $transfer->transit; - $messages->{'WasTransfered'} = $transfer->tobranch; - } - else { + $messages->{'TransferTo'} = $transfer->tobranch; + $messages->{'WasTransfered'} = $transfer->id; + } else { $messages->{'WrongTransfer'} = $transfer->tobranch; $messages->{'WrongTransferItem'} = $item->itemnumber; } @@ -2521,8 +2520,9 @@ sub AddReturn { (C4::Context->preference("UseBranchTransferLimits") and ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType ) )) { - ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 }); - $messages->{'WasTransfered'} = $returnbranch; + my $transfer = ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 }); + $messages->{'TransferTo'} = $returnbranch; + $messages->{'WasTransfered'} = $transfer->id; $messages->{'TransferTrigger'} = $transfer_trigger; } else { $messages->{'NeedsTransfer'} = $returnbranch; diff --git a/C4/Items.pm b/C4/Items.pm index d2fa257ef5e..37afaa8f04a 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -386,7 +386,7 @@ sub ModItemTransfer { $transfer->transit({ skip_record_index => $params->{skip_record_index} }); } - return; + return $transfer; } =head2 ModDateLastSeen diff --git a/Koha/Item.pm b/Koha/Item.pm index 0f2dc167b44..f41736c94d9 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -795,9 +795,13 @@ we still expect the item to end up at a final location eventually. sub get_transfer { my ($self) = @_; + my $transfers = $self->_result->current_branchtransfers->search( + undef, + { 'order_by' => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] } + ); - my $transfer = $self->_result->current_branchtransfers->next; - return Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer; + my $transfer = $transfers->next; + return Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer; } =head3 transfer @@ -841,9 +845,12 @@ we still expect the item to end up at a final location eventually. sub get_transfers { my ($self) = @_; - my $transfer_rs = $self->_result->current_branchtransfers; + my $transfers_rs = $self->_result->current_branchtransfers->search( + undef, + { 'order_by' => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] } + ); - return Koha::Item::Transfers->_new_from_dbic($transfer_rs); + return Koha::Item::Transfers->_new_from_dbic($transfers_rs); } =head3 last_returned_by diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index cc428b0a837..c543c0871e1 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -1048,8 +1048,7 @@ __PACKAGE__->has_many( "$args->{foreign_alias}.datearrived" => undef, "$args->{foreign_alias}.datecancelled" => undef, }; - }, - { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ] } + } ); # Relationship with bundled items diff --git a/circ/returns.pl b/circ/returns.pl index 5b119e3726b..034cfd06020 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -520,10 +520,11 @@ my $recalled = 0; if ( $messages->{'WasTransfered'} ) { $template->param( - found => 1, - transfer => $messages->{'WasTransfered'}, - trigger => $messages->{'TransferTrigger'}, - itemnumber => $itemnumber, + found => 1, + transfer => $messages->{'WasTransfered'}, + transferto => $messages->{'TransferTo'}, + trigger => $messages->{'TransferTrigger'}, + itemnumber => $itemnumber, ); } @@ -697,6 +698,9 @@ foreach my $code ( keys %$messages ) { elsif ( $code eq 'WasTransfered' ) { ; # FIXME... anything to do here? } + elsif ( $code eq 'TransferTo' ) { + ; # Handled above, along with WasTransfered + } elsif ( $code eq 'withdrawn' ) { $err{withdrawn} = 1; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index ab891c58c2e..19f5fa76487 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -122,7 +122,7 @@ [% END # /IF hold_auto_filled %] - [% IF ( trigger ) %] + [% IF ( trigger && !transfertodo ) %]

Reason for transfer

@@ -745,7 +745,7 @@