Bug 25344: Add support for circulation status 10 ( item in transit )
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 1 May 2020 16:04:37 +0000 (12:04 -0400)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 13 Aug 2020 08:15:33 +0000 (10:15 +0200)
We should support the SIP2 "circulation status" value 10, "in transit
between library locations"

Test Plan:
1) Apply this patch
2) prove t/db_dependent/SIP/Transaction.t

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/SIP/ILS/Item.pm
t/db_dependent/SIP/Transaction.t

index 340fc67..d5e6136 100644 (file)
@@ -83,10 +83,11 @@ sub new {
         return;
     }
     my $self = $item->unblessed;
-    $self->{      'id'       } = $item->barcode;     # to SIP, the barcode IS the id.
-    $self->{permanent_location}= $item->homebranch;
-    $self->{'collection_code'} = $item->ccode;
-    $self->{  'call_number'  } = $item->itemcallnumber;
+    $self->{_object}            = $item;
+    $self->{id}                 = $item->barcode; # to SIP, the barcode IS the id.
+    $self->{permanent_location} = $item->homebranch;
+    $self->{collection_code}    = $item->ccode;
+    $self->{call_number}        = $item->itemcallnumber;
 
     $self->{object} = $item;
 
@@ -257,7 +258,10 @@ sub title_id {
 
 sub sip_circulation_status {
     my $self = shift;
-    if ( $self->{borrowernumber} ) {
+    if ( $self->{_object}->get_transfer ) {
+        return '10'; # in transit between libraries
+    }
+    elsif ( $self->{borrowernumber} ) {
         return '04';    # charged
     }
     elsif ( grep { $_->{itemnumber} == $self->{itemnumber}  } @{ $self->{hold_shelf} } ) {
index cb10003..a09cd34 100755 (executable)
@@ -4,7 +4,7 @@
 # Current state is very rudimentary. Please help to extend it!
 
 use Modern::Perl;
-use Test::More tests => 10;
+use Test::More tests => 11;
 
 use Koha::Database;
 use t::lib::TestBuilder;
@@ -20,6 +20,7 @@ use C4::SIP::ILS::Transaction::Checkin;
 
 use C4::Reserves;
 use Koha::CirculationRules;
+use Koha::Item::Transfer;
 use Koha::DateUtils qw( dt_from_string output_pref );
 
 my $schema = Koha::Database->new->schema;
@@ -396,4 +397,44 @@ subtest checkin_withdrawn => sub {
     $circ = $ils->checkin( $item->barcode, C4::SIP::Sip::timestamp );
     is( $circ->{screen_msg}, 'Item not checked out', "Got 'Item not checked out' screen message" );
 };
+
+subtest item_circulation_status => sub {
+    plan tests => 2;
+
+    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
+
+    my $patron = $builder->build_object(
+        {
+            class => 'Koha::Patrons',
+            value => {
+                branchcode => $library->branchcode,
+            }
+        }
+    );
+
+    t::lib::Mocks::mock_userenv(
+        { branchcode => $library->branchcode, flags => 1 } );
+
+    my $item = $builder->build_sample_item(
+        {
+            library => $library->branchcode,
+        }
+    );
+
+    my $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
+    my $status = $sip_item->sip_circulation_status;
+    is( $status, '03', "Item circulation status is available");
+
+    my $transfer = Koha::Item::Transfer->new({
+        itemnumber => $item->id,
+        datesent   => '2020-01-01',
+        frombranch => $library->branchcode,
+        tobranch   => $library2->branchcode,
+    })->store();
+
+    $sip_item = C4::SIP::ILS::Item->new( $item->barcode );
+    $status = $sip_item->sip_circulation_status;
+    is( $status, '10', "Item circulation status is in transit" );
+};
 $schema->storage->txn_rollback;