@@ -, +, @@ wait for the user to actually confirm that's the case transfers for any other reason from display prefetch completely nukes the order_by that this transfer method relies heavily upon to get the right modified FIFO transfer of the queue. --- C4/Circulation.pm | 12 +++---- C4/Items.pm | 2 +- Koha/Item.pm | 1 - Koha/Schema/Result/Item.pm | 34 ++++++++++++------- catalogue/detail.pl | 2 +- circ/returns.pl | 4 +++ .../prog/en/modules/circ/returns.tt | 5 +-- 7 files changed, 37 insertions(+), 23 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2376,10 +2376,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; } @@ -2529,8 +2528,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; --- a/C4/Items.pm +++ a/C4/Items.pm @@ -386,7 +386,7 @@ sub ModItemTransfer { $transfer->transit({ skip_record_index => $params->{skip_record_index} }); } - return; + return $transfer; } =head2 ModDateLastSeen --- a/Koha/Item.pm +++ a/Koha/Item.pm @@ -776,7 +776,6 @@ we still expect the item to end up at a final location eventually. sub get_transfer { my ($self) = @_; - my $transfer = $self->_result->current_branchtransfers->next; return Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer; } --- a/Koha/Schema/Result/Item.pm +++ a/Koha/Schema/Result/Item.pm @@ -1013,19 +1013,29 @@ __PACKAGE__->many_to_many( "ordernumber", ); +#__PACKAGE__->has_many( +# "current_branchtransfers", +# "Koha::Schema::Result::Branchtransfer", +# sub { +# my $args = shift; +# +# return { +# "$args->{foreign_alias}.itemnumber" => { -ident => "$args->{self_alias}.itemnumber" }, +# "$args->{foreign_alias}.datearrived" => undef, +# "$args->{foreign_alias}.datecancelled" => undef, +# }; +# }, +# { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ] } +#); + __PACKAGE__->has_many( - "current_branchtransfers", - "Koha::Schema::Result::Branchtransfer", - sub { - my $args = shift; - - return { - "$args->{foreign_alias}.itemnumber" => { -ident => "$args->{self_alias}.itemnumber" }, - "$args->{foreign_alias}.datearrived" => undef, - "$args->{foreign_alias}.datecancelled" => undef, - }; - }, - { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ] } + "current_branchtransfers", + "Koha::Schema::Result::Branchtransfer", + { "foreign.itemnumber" => "self.itemnumber" }, + { + where => { 'datearrived' => undef, 'datecancelled' => undef }, + order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ] + } ); # Relationship with bundled items --- a/catalogue/detail.pl +++ a/catalogue/detail.pl @@ -196,7 +196,7 @@ $params->{ itemlost } = 0 if $patron->category->hidelostitems && !$showallitems; my $items_params = { ( $invalid_marc_record ? () : ( host_items => 1 ) ), }; -my $items = $biblio->items($items_params)->search_ordered( $params, { prefetch => ['issue','current_branchtransfers'] } ); +my $items = $biblio->items($items_params)->search_ordered( $params, { prefetch => ['issue'] } ); # flag indicating existence of at least one item linked via a host record my $hostrecords = $biblio->host_items->count; --- a/circ/returns.pl +++ a/circ/returns.pl @@ -521,6 +521,7 @@ if ( $messages->{'WasTransfered'} ) { $template->param( found => 1, transfer => $messages->{'WasTransfered'}, + transferto => $messages->{'TransferTo'}, trigger => $messages->{'TransferTrigger'}, itemnumber => $itemnumber, ); @@ -696,6 +697,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; } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -121,7 +121,7 @@ [% END # /IF hold_auto_filled %] - [% IF ( trigger ) %] + [% IF ( trigger && !transfertodo ) %]