From 5ad5798eb0e0104b2d187b602dfa8d303f3bd97f Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 30 Sep 2019 10:37:03 +0000 Subject: [PATCH] Bug 23695: Alter transferbook to take a hash of params and specify from_branch To test: 1 - Go to Circulation->Transfer 2 - Find an item from your branch and create a transfer to branch B 3 - Note you can specify the origin and default is 'Item's holding library' 4 - Confirm the item is marked as held at your current branch and is being transferred to B 5 - Find an item from a third branch, branch C 6 - Transfer that item to branch B from branch D 7 - Confirm the item is held at branch D and is being transferred to B 8 - prove -v t/db_dependent/Circulation.t 9 - prove -v t/db_dependent/Koha/Items.t 10 - prove -v t/db_dependent/RotatingCollections.t --- C4/Circulation.pm | 18 +++++++--- C4/RotatingCollections.pm | 7 +++- circ/branchtransfers.pl | 15 +++++--- .../prog/en/modules/circ/branchtransfers.tt | 11 ++++++ t/db_dependent/Circulation.t | 41 +++++++++++++++++++--- t/db_dependent/Koha/Items.t | 6 +++- 6 files changed, 82 insertions(+), 16 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index dc12cd3352..53c21242a6 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -250,12 +250,17 @@ sub decode { =head2 transferbook - ($dotransfer, $messages, $iteminformation) = &transferbook($newbranch, - $barcode, $ignore_reserves); + ($dotransfer, $messages, $iteminformation) = &transferbook({ + from_branch => $frombranch + to_branch => $tobranch, + barcode => $barcode, + ignore_reserves => $ignore_reserves + }); Transfers an item to a new branch. If the item is currently on loan, it is automatically returned before the actual transfer. -C<$newbranch> is the code for the branch to which the item should be transferred. +C<$fbr> is the code for the branch initiating the transfer. +C<$tbr> is the code for the branch to which the item should be transferred. C<$barcode> is the barcode of the item to be transferred. @@ -303,7 +308,11 @@ The item was eligible to be transferred. Barring problems communicating with the =cut sub transferbook { - my ( $tbr, $barcode, $ignoreRs ) = @_; + my $params = shift; + my $tbr = $params->{to_branch}; + my $fbr = $params->{from_branch}; + my $ignoreRs = $params->{ignore_reserves}; + my $barcode = $params->{barcode}; my $messages; my $dotransfer = 1; my $item = Koha::Items->find( { barcode => $barcode } ); @@ -318,7 +327,6 @@ sub transferbook { my $itemnumber = $item->itemnumber; # get branches of book... my $hbr = $item->homebranch; - my $fbr = $item->holdingbranch; # if using Branch Transfer Limits if ( C4::Context->preference("UseBranchTransferLimits") == 1 ) { diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm index 709eaf2164..8e6a560a7b 100644 --- a/C4/RotatingCollections.pm +++ b/C4/RotatingCollections.pm @@ -446,7 +446,12 @@ sub TransferCollection { while ( my $item = $sth->fetchrow_hashref ) { my ($status) = CheckReserves( $item->{itemnumber} ); my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} ); - C4::Circulation::transferbook( $colBranchcode, $item->{barcode}, my $ignore_reserves = 1 ) unless ( $status eq 'Waiting' || @transfers ); + C4::Circulation::transferbook({ + from_branch => $item->holdingbranch, + to_branch => $colBranchcode, + barcode => $item->{barcode}, + ignore_reserves => 1 + }) unless ( $status eq 'Waiting' || @transfers ); } return 1; diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl index f65402d412..ae2c8f05c6 100755 --- a/circ/branchtransfers.pl +++ b/circ/branchtransfers.pl @@ -80,6 +80,7 @@ my $setwaiting; my $request = $query->param('request') || ''; my $borrowernumber = $query->param('borrowernumber') || 0; +my $frombranchcd = $query->param('frombranchcd') || C4::Context->userenv->{'branch'}; my $tobranchcd = $query->param('tobranchcd') || ''; my $ignoreRs = 0; @@ -126,14 +127,19 @@ defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter # warn "barcode : $barcode"; if ($barcode) { - ( $transferred, $messages ) = - transferbook( $tobranchcd, $barcode, $ignoreRs ); my $item = Koha::Items->find({ barcode => $barcode }); + $frombranchcd = $item->holdingbranch if $frombranchcd eq "current_holding"; + ( $transferred, $messages ) = + transferbook({ + from_branch => $frombranchcd, + to_branch => $tobranchcd, + barcode => $barcode, + ignore_reserves => $ignoreRs + }); $found = $messages->{'ResFound'}; if ($transferred) { my %item; my $biblio = $item->biblio; - my $frbranchcd = C4::Context->userenv->{'branch'}; $item{'biblionumber'} = $item->biblionumber; $item{'itemnumber'} = $item->itemnumber; $item{'title'} = $biblio->title; @@ -145,7 +151,7 @@ if ($barcode) { $item{'location'} = $av->count ? $av->next->lib : ''; $item{counter} = 0; $item{barcode} = $barcode; - $item{frombrcd} = $frbranchcd; + $item{frombrcd} = $frombranchcd; $item{tobrcd} = $tobranchcd; push( @trsfitemloop, \%item ); } @@ -235,6 +241,7 @@ $template->param( itemnumber => $itemnumber, barcode => $barcode, biblionumber => $biblionumber, + frombranchcd => $frombranchcd, tobranchcd => $tobranchcd, reqmessage => $reqmessage, cancelled => $cancelled, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt index 4859333a3b..d270733310 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt @@ -71,6 +71,7 @@ + @@ -127,6 +128,7 @@ [% ELSE %]
  • Collection code: [% AuthorisedValues.GetByCode( 'CCODE', errmsgloo.code ) | html %]
  • [% END %] +
  • Originating library: [% Branches.GetName( errmsgloo.fbr ) | html %]
  • Destination library: [% Branches.GetName( errmsgloo.tbr ) | html %]
  • @@ -150,6 +152,13 @@ Transfer
    1. + + +
    2. +