| Lines 54-59
          use C4::Log qw( logaction );
      
      
        Link Here | 
        
          | 54 | use List::MoreUtils qw( any ); | 54 | use List::MoreUtils qw( any ); | 
        
          | 55 | use DateTime::Format::MySQL; | 55 | use DateTime::Format::MySQL; | 
        
          | 56 |                   # debugging; so please don't remove this | 56 |                   # debugging; so please don't remove this | 
            
              |  |  | 57 | use Try::Tiny qw( catch try ); | 
        
          | 57 |  | 58 |  | 
        
          | 58 | use Koha::AuthorisedValues; | 59 | use Koha::AuthorisedValues; | 
        
          | 59 | use Koha::DateUtils qw( dt_from_string ); | 60 | use Koha::DateUtils qw( dt_from_string ); | 
  
    | Lines 359-389
          The last optional parameter allows for passing skip_record_index through to the
      
      
        Link Here | 
        
          | 359 | sub ModItemTransfer { | 360 | sub ModItemTransfer { | 
        
          | 360 |     my ( $itemnumber, $frombranch, $tobranch, $trigger, $params ) = @_; | 361 |     my ( $itemnumber, $frombranch, $tobranch, $trigger, $params ) = @_; | 
        
          | 361 |  | 362 |  | 
          
            
              | 362 |     my $dbh = C4::Context->dbh; | 363 |     my $dbh  = C4::Context->dbh; | 
            
              | 363 |     my $item = Koha::Items->find( $itemnumber ); | 364 |     my $item = Koha::Items->find($itemnumber); | 
        
          | 364 |  | 365 |  | 
        
          | 365 |     # NOTE: This retains the existing hard coded behaviour by ignoring transfer limits | 366 |     # NOTE: This retains the existing hard coded behaviour by ignoring transfer limits | 
        
          | 366 |     # and always replacing any existing transfers. (In theory, calls to ModItemTransfer | 367 |     # and always replacing any existing transfers. (In theory, calls to ModItemTransfer | 
        
          | 367 |     # will have been preceded by a check of branch transfer limits) | 368 |     # will have been preceded by a check of branch transfer limits) | 
        
          | 368 |     my $to_library = Koha::Libraries->find($tobranch); | 369 |     my $to_library = Koha::Libraries->find($tobranch); | 
          
            
              | 369 |     my $transfer = $item->request_transfer( | 370 |     my $transfer; | 
            
              | 370 |         { | 371 |     try { | 
            
              | 371 |             to            => $to_library, | 372 |         $transfer = $item->request_transfer( | 
            
              | 372 |             reason        => $trigger, | 373 |             { | 
            
              | 373 |             ignore_limits => 1, | 374 |                 to            => $to_library, | 
            
              | 374 |             replace       => 1 | 375 |                 reason        => $trigger, | 
            
              |  |  | 376 |                 ignore_limits => 1, | 
            
              | 377 |             } | 
            
              | 378 |         ); | 
            
              | 379 |     } catch { | 
            
              | 380 |         if ( $_->isa('Koha::Exceptions::Item::Transfer::InQueue') ) { | 
            
              | 381 |             my $exception      = $_; | 
            
              | 382 |             my $found_transfer = $_->transfer; | 
            
              | 383 |  | 
            
              | 384 |             # If StockRotationAdvance, leave in place but ensure transit state is reset | 
            
              | 385 |             if ( $found_transfer->reason eq 'StockrotationAdvance' ) { | 
            
              | 386 |                 $transfer = $item->request_transfer( | 
            
              | 387 |                     { | 
            
              | 388 |                         to            => $to_library, | 
            
              | 389 |                         reason        => $trigger, | 
            
              | 390 |                         ignore_limits => 1, | 
            
              | 391 |                         enqueue       => 1 | 
            
              | 392 |                     } | 
            
              | 393 |                 ); | 
            
              | 394 |  | 
            
              | 395 |                 # Ensure transit is reset | 
            
              | 396 |                 $found_transfer->datesent(undef)->store; | 
            
              | 397 |             } else { | 
            
              | 398 |                 $transfer = $item->request_transfer( | 
            
              | 399 |                     { | 
            
              | 400 |                         to            => $to_library, | 
            
              | 401 |                         reason        => $trigger, | 
            
              | 402 |                         ignore_limits => 1, | 
            
              | 403 |                         replace       => 1 | 
            
              | 404 |                     } | 
            
              | 405 |                 ); | 
            
              | 406 |             } | 
            
              | 407 |         } else { | 
            
              | 408 |             $_->rethrow(); | 
        
          | 375 |         } | 409 |         } | 
          
            
              | 376 |     ); | 410 |     }; | 
        
          | 377 |  | 411 |  | 
        
          | 378 |     # Immediately set the item to in transit if it is checked in | 412 |     # Immediately set the item to in transit if it is checked in | 
        
          | 379 |     if ( !$item->checkout ) { | 413 |     if ( !$item->checkout ) { | 
        
          | 380 |         $item->holdingbranch($frombranch)->store( | 414 |         $item->holdingbranch($frombranch)->store( | 
        
          | 381 |             { | 415 |             { | 
        
          | 382 |                 log_action        => 0, | 416 |                 log_action        => 0, | 
          
            
              | 383 |                 skip_record_index => 1, # avoid indexing duplication, let ->transit handle it | 417 |                 skip_record_index => 1,    # avoid indexing duplication, let ->transit handle it | 
        
          | 384 |             } | 418 |             } | 
        
          | 385 |         ); | 419 |         ); | 
          
            
              | 386 |         $transfer->transit({ skip_record_index => $params->{skip_record_index} }); | 420 |         $transfer->transit( { skip_record_index => $params->{skip_record_index} } ); | 
        
          | 387 |     } | 421 |     } | 
        
          | 388 |  | 422 |  | 
        
          | 389 |     return $transfer; | 423 |     return $transfer; |