Bug 32997: Add REST API endpoint to list authorised values for multiple given categories
[srvgit] / Koha / Item / Transfer.pm
index c9e3206..286e0fd 100644 (file)
@@ -17,12 +17,11 @@ package Koha::Item::Transfer;
 
 use Modern::Perl;
 
-use Carp;
 
-use C4::Items;
+use C4::Items qw( CartToShelf ModDateLastSeen );
 
 use Koha::Database;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string );
 use Koha::Exceptions::Item::Transfer;
 
 use base qw(Koha::Object);
@@ -51,6 +50,34 @@ sub item {
     return Koha::Item->_new_from_dbic($item_rs);
 }
 
+=head3 from_library
+
+  my $from_library = $transfer->from_library;
+
+Returns the associated from_library for this transfer.
+
+=cut
+
+sub from_library {
+    my ($self) = @_;
+    my $from_library_rs = $self->_result->frombranch;
+    return Koha::Library->_new_from_dbic($from_library_rs);
+}
+
+=head3 to_library
+
+  my $to_library = $transfer->to_library;
+
+Returns the associated to_library for this transfer.
+
+=cut
+
+sub to_library {
+    my ($self) = @_;
+    my $to_library_rs = $self->_result->tobranch;
+    return Koha::Library->_new_from_dbic($to_library_rs);
+}
+
 =head3 transit
 
 Set the transfer as in transit by updating the datesent time.
@@ -63,7 +90,7 @@ sub transit {
     my ($self) = @_;
 
     # Throw exception if item is still checked out
-    Koha::Exceptions::Item::Transfer::Out->throw() if ( $self->item->checkout );
+    Koha::Exceptions::Item::Transfer::OnLoan->throw() if ( $self->item->checkout );
 
     # Remove the 'shelving cart' location status if it is being used (Bug 3701)
     CartToShelf( $self->item->itemnumber )
@@ -94,7 +121,9 @@ Boolean returning whether the transfer is in transit or waiting
 sub in_transit {
     my ($self) = @_;
 
-    return ( defined( $self->datesent ) && !defined( $self->datearrived ) );
+    return ( defined( $self->datesent )
+          && !defined( $self->datearrived )
+          && !defined( $self->datecancelled ) );
 }
 
 =head3 receive
@@ -107,7 +136,7 @@ sub receive {
     my ($self) = @_;
 
     # Throw exception if item is checked out
-    Koha::Exceptions::Item::Transfer::Out->throw() if ($self->item->checkout);
+    Koha::Exceptions::Item::Transfer::OnLoan->throw() if ($self->item->checkout);
 
     # Update the arrived date
     $self->set({ datearrived => dt_from_string })->store;
@@ -132,7 +161,7 @@ sub cancel {
       unless defined($params->{reason});
 
     # Throw exception if item is in transit already
-    Koha::Exceptions::Item::Transfer::Transit->throw() if ( !$params->{force} && $self->in_transit );
+    Koha::Exceptions::Item::Transfer::InTransit->throw() if ( !$params->{force} && $self->in_transit );
 
     # Update the cancelled date
     $self->set(