Bug 19380: Add transfer informations in ILS-DI GetRecords response
authorJulian Maurice <julian.maurice@biblibre.com>
Wed, 27 Sep 2017 13:32:53 +0000 (15:32 +0200)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 29 Mar 2019 13:18:09 +0000 (13:18 +0000)
Test plan:
1. Put an item into a 'transfer' state
  a. Place a hold on an item in branch A for a patron of branch B
  b. Check in this item in branch A and confirm transfer
2. Go to http://opac/cgi-bin/koha/ilsdi.pl?service=GetRecords&id=XXX
   where XXX is the biblionumber of the biblio the item belongs to.
3. Verify you have a new <transfer> element inside //record/items/item
   that contains <datesent>, <frombranch> and <tobranch>
4. Check in the same item in branch B, so that the item is not flagged
   as being transferred
5. Repeat 2
6. Verify that the <transfer> element is not there.
7. prove t/db_dependent/ILSDI_Services.t

Followed test plan, patch worked as described. Also ran QA test tools
and modified files passed

Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

C4/ILSDI/Services.pm
t/db_dependent/ILSDI_Services.t

index a1e23cf..a629a1c 100644 (file)
@@ -243,6 +243,15 @@ sub GetRecords {
             my $holding_library = Koha::Libraries->find( $item->{holdingbranch} );
             $item->{'homebranchname'}    = $home_library    ? $home_library->branchname    : '';
             $item->{'holdingbranchname'} = $holding_library ? $holding_library->branchname : '';
+
+            my ($transferDate, $transferFrom, $transferTo) = GetTransfers($item->{itemnumber});
+            if ($transferDate) {
+                $item->{transfer} = {
+                    datesent => $transferDate,
+                    frombranch => $transferFrom,
+                    tobranch => $transferTo,
+                };
+            }
         }
 
         # Hashref building...
index 1c93ba9..0e50c8e 100644 (file)
@@ -19,11 +19,14 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 
-use Test::More tests => 6;
+use Test::More tests => 7;
 use Test::MockModule;
 use t::lib::Mocks;
 use t::lib::TestBuilder;
 
+use C4::Items qw( ModItemTransfer );
+use C4::Circulation qw( GetTransfers );
+
 use Koha::AuthUtils;
 
 BEGIN {
@@ -242,7 +245,6 @@ subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes
     $schema->storage->txn_rollback;
 };
 
-
 subtest 'LookupPatron test' => sub {
 
     plan tests => 9;
@@ -540,4 +542,58 @@ subtest 'Holds test for branch transfer limits' => sub {
     is( $reply->{code}, undef, "Record hold, Item con be transferred" );
 
     $schema->storage->txn_rollback;
-}
+};
+
+subtest 'GetRecords' => sub {
+
+    plan tests => 1;
+
+    $schema->storage->txn_begin;
+
+    t::lib::Mocks::mock_preference( 'ILS-DI', 1 );
+
+    my $branch1 = $builder->build({
+        source => 'Branch',
+    });
+    my $branch2 = $builder->build({
+        source => 'Branch',
+    });
+
+    my $biblio = $builder->build({
+        source => 'Biblio',
+    });
+    my $biblioitem = $builder->build({
+        source => 'Biblioitem',
+        value => {
+            biblionumber => $biblio->{biblionumber},
+        },
+    });
+    my $item = $builder->build({
+        source => 'Item',
+        value => {
+            biblionumber => $biblio->{biblionumber},
+            biblioitemnumber => $biblioitem->{biblioitemnumber},
+            homebranch => $branch1->{branchcode},
+            holdingbranch => $branch1->{branchcode},
+        },
+    });
+
+    ModItemTransfer($item->{itemnumber}, $branch1->{branchcode}, $branch2->{branchcode});
+
+    my $cgi = new CGI;
+    $cgi->param(service => 'GetRecords');
+    $cgi->param(id => $biblio->{biblionumber});
+
+    my $reply = C4::ILSDI::Services::GetRecords($cgi);
+
+    my ($datesent, $frombranch, $tobranch) = GetTransfers($item->{itemnumber});
+    my $expected = {
+        datesent => $datesent,
+        frombranch => $frombranch,
+        tobranch => $tobranch,
+    };
+    is_deeply($reply->{record}->[0]->{items}->{item}->[0]->{transfer}, $expected,
+        'GetRecords returns transfer informations');
+
+    $schema->storage->txn_rollback;
+};