From 2b08985978c09c0e3ad48a9de5b706ca28217eb3 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 27 Sep 2017 15:32:53 +0200 Subject: [PATCH] Bug 19380: Add transfer informations in ILS-DI GetRecords response 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 element inside //record/items/item that contains , and 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 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 --- C4/ILSDI/Services.pm | 9 +++++++ t/db_dependent/ILSDI_Services.t | 58 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index a0aec99..b70c542 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -239,6 +239,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... diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 7677db0..81295d9 100644 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -19,11 +19,14 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use Test::More tests => 3; +use Test::More tests => 4; 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 { @@ -198,3 +201,56 @@ subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes $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; +}; -- 2.1.4