From 6666918dd661b0207366becefd1480257197a353 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 19 Mar 2019 14:16:06 +0100 Subject: [PATCH] Bug 19380: Use Koha::Item::get_transfer instead of GetTransfers Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- C4/ILSDI/Services.pm | 34 ++++++++++++++++++--------------- t/db_dependent/ILSDI_Services.t | 15 +++++++-------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index a629a1ce78..fffb497ff4 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -230,32 +230,36 @@ sub GetRecords { my $biblioitemnumber = $biblioitem->{'biblioitemnumber'}; my $holds = $biblio->current_holds->unblessed; my $issues = GetBiblioIssues($biblionumber); - my $items = $biblio->items->unblessed; + my @items = $biblio->items; + + $biblioitem->{items}->{item} = []; # We loop over the items to clean them - foreach my $item (@$items) { + foreach my $item (@items) { + my %item = %{ $item->unblessed }; # This hides additionnal XML subfields, we don't need these info - delete $item->{'more_subfields_xml'}; + delete $item{'more_subfields_xml'}; # Display branch names instead of branch codes - my $home_library = Koha::Libraries->find( $item->{homebranch} ); - 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, + my $home_library = $item->home_branch; + my $holding_library = $item->holding_branch; + $item{'homebranchname'} = $home_library ? $home_library->branchname : ''; + $item{'holdingbranchname'} = $holding_library ? $holding_library->branchname : ''; + + my $transfer = $item->get_transfer; + if ($transfer) { + $item{transfer} = { + datesent => $transfer->datesent, + frombranch => $transfer->frombranch, + tobranch => $transfer->tobranch, }; } + + push @{ $biblioitem->{items}->{item} }, \%item; } # Hashref building... - $biblioitem->{'items'}->{'item'} = $items; $biblioitem->{'reserves'}->{'reserve'} = $holds; $biblioitem->{'issues'}->{'issue'} = $issues; diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 0e50c8e3ae..d102836386 100644 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -25,7 +25,6 @@ use t::lib::Mocks; use t::lib::TestBuilder; use C4::Items qw( ModItemTransfer ); -use C4::Circulation qw( GetTransfers ); use Koha::AuthUtils; @@ -568,8 +567,8 @@ subtest 'GetRecords' => sub { biblionumber => $biblio->{biblionumber}, }, }); - my $item = $builder->build({ - source => 'Item', + my $item = $builder->build_object({ + class => 'Koha::Items', value => { biblionumber => $biblio->{biblionumber}, biblioitemnumber => $biblioitem->{biblioitemnumber}, @@ -578,7 +577,7 @@ subtest 'GetRecords' => sub { }, }); - ModItemTransfer($item->{itemnumber}, $branch1->{branchcode}, $branch2->{branchcode}); + ModItemTransfer($item->itemnumber, $branch1->{branchcode}, $branch2->{branchcode}); my $cgi = new CGI; $cgi->param(service => 'GetRecords'); @@ -586,11 +585,11 @@ subtest 'GetRecords' => sub { my $reply = C4::ILSDI::Services::GetRecords($cgi); - my ($datesent, $frombranch, $tobranch) = GetTransfers($item->{itemnumber}); + my $transfer = $item->get_transfer; my $expected = { - datesent => $datesent, - frombranch => $frombranch, - tobranch => $tobranch, + datesent => $transfer->datesent, + frombranch => $transfer->frombranch, + tobranch => $transfer->tobranch, }; is_deeply($reply->{record}->[0]->{items}->{item}->[0]->{transfer}, $expected, 'GetRecords returns transfer informations'); -- 2.39.5