From 788b81eed608a582cfff86ac711e217b9c3f6379 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 18 Dec 2020 16:29:32 +0000 Subject: [PATCH] Bug 24446: Update ModItemTransfer for daterequested/datecancelled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C4::Items::ModItemTransfer is used throughout the codebase and currently it will never set the daterequested or datecancelled fields. With the modifications to how circulation deals with transfers we need to update this function to set those fields appropriately. Functionality has been retained, ModItemTransfer will continue to add a transfer regardless of limits or current transits existing. Signed-off-by: Kathleen Milne Signed-off-by: Joonas Kylmälä --- C4/Items.pm | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 527e11c73b..d7323655cb 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -350,20 +350,30 @@ sub ModItemTransfer { my $dbh = C4::Context->dbh; my $item = Koha::Items->find( $itemnumber ); - # Remove the 'shelving cart' location status if it is being used. - CartToShelf( $itemnumber ) if $item->location && $item->location eq 'CART' && ( !$item->permanent_location || $item->permanent_location ne 'CART' ); - - $dbh->do("UPDATE branchtransfers SET datearrived = NOW(), comments = ? WHERE itemnumber = ? AND datearrived IS NULL", undef, "Canceled, new transfer from $frombranch to $tobranch created", $itemnumber); + # NOTE: This retains the existing hard coded behaviour by ignoring transfer limits + # and always replacing any existing transfers. (In theory, calls to ModItemTransfer + # will have been preceded by a check of branch transfer limits) + my $to_library = Koha::Libraries->find($tobranch); + my $transfer = $item->request_transfer( + { + to => $to_library, + reason => $trigger, + ignore_limits => 1, + replace => 1 + } + ); - #new entry in branchtransfers.... - my $sth = $dbh->prepare( - "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch, reason) - VALUES (?, ?, NOW(), ?, ?)"); - $sth->execute($itemnumber, $frombranch, $tobranch, $trigger); + # Immediately set the item to in transit if it is checked in + if ( !$item->checkout ) { + $item->holdingbranch($frombranch)->store( + { + log_action => 0, + skip_record_index => $params->{skip_record_index} + } + ); + $transfer->transit; + } - # FIXME we are fetching the item twice in the 2 next statements! - Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ log_action => 0, skip_record_index => $params->{skip_record_index} }); - ModDateLastSeen($itemnumber, undef, { skip_record_index => $params->{skip_record_index} }); return; } -- 2.20.1