Bug 23695: Alter transferbook to take a hash of params and specify from_branch
authorNick <nick@bywatersolutions.com>
Mon, 30 Sep 2019 10:37:03 +0000 (10:37 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 18 Aug 2020 13:45:48 +0000 (15:45 +0200)
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

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

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

circ/branchtransfers.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt
t/db_dependent/Circulation.t

index 1e9f48c..b5e807b 100755 (executable)
@@ -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;
@@ -223,6 +224,7 @@ $template->param(
     itemnumber              => $itemnumber,
     barcode                 => $barcode,
     biblionumber            => $biblionumber,
+    frombranchcd            => $frombranchcd,
     tobranchcd              => $tobranchcd,
     reqmessage              => $reqmessage,
     cancelled               => $cancelled,
index 5eb69ed..b640cf0 100644 (file)
@@ -72,6 +72,7 @@
                             <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
                             <input type="hidden" name="borrowernumber" value="[% borrowernumber | html %]" />
                             <input type="hidden" name="tobranchcd" value="[% tobranchcd | html %]" />
+                            <input type="hidden" name="frombranchcd" value="[% tobranchcd | html %]" />
                             <input type="hidden" name="barcode" value="[% barcode | html %]" />
                             <input type="hidden" name="request" value="KillReserved" />
                             <input type="submit" value="Cancel" />
                                           [% ELSE %]
                                               <li>Collection: <b>[% AuthorisedValues.GetByCode( 'CCODE', errmsgloo.code ) | html %]</b></li>
                                           [% END %]
+                                          <li>Originating library: <b>[% Branches.GetName( errmsgloo.fbr ) | html %]</b></li>
                                           <li>Destination library: <b>[% Branches.GetName( errmsgloo.tbr ) | html %]</b></li>
                                       </ol>
                                   </li>
             <legend>Transfer</legend>
             <ol>
                        <li>
+                <label for="frombranchcd">Originating library: </label>
+                    <select name="frombranchcd" id="frombranchcd">
+                        <option value="current_holding">Item's holding branch</option>
+                        [% PROCESS options_for_libraries libraries => Branches.all( selected => '', unfiltered => 1) %]
+                    </select>
+            </li>
+            <li>
                 <label for="tobranchcd">Destination library: </label>
                     <select name="tobranchcd" id="tobranchcd">
                         [% PROCESS options_for_libraries libraries => Branches.all( selected => tobranchcd, unfiltered => 1) %]
                 <th class="tf-itemcallnumber">Call number</th>
                 <th class="tf-itemtype">Item type</th>
                 <th class="tf-ccode">Collection</th>
+                <th class="tf-origin">Origin</th>
                 <th class="tf-destination">Destination</th>
             </tr>
             [% FOREACH trsfitemloo IN trsfitemloop %]
                     <td class="tf-itemcallnumber">[% trsfitemloo.item.itemcallnumber | html %]</td>
                     <td class="tf-itemtype">[% ItemTypes.GetDescription( trsfitemloo.item.effective_itemtype ) | html %]</td>
                     <td class="tf-ccode">[% AuthorisedValues.GetByCode( 'CCODE', trsfitemloo.item.ccode ) | html %]</td>
+                    <td class="tf-origin">[% Branches.GetName( trsfitemloo.frombrcd ) | html %]</td>
                     <td class="tf-destination">[% Branches.GetName( trsfitemloo.tobrcd ) | html %]</td>
                 </tr>
             [% END %]
index f3f2671..22446cd 100755 (executable)
@@ -18,7 +18,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 49;
+use Test::More tests => 50;
 use Test::MockModule;
 use Test::Deep qw( cmp_deeply );
 
@@ -3293,6 +3293,32 @@ subtest 'Cancel transfers on lost items' => sub {
     is( $tobranch, undef, 'The transfer on the lost item has been deleted as the LostItemCancelOutstandingTransfer is enabled');
     $itemcheck = Koha::Items->find($item->itemnumber);
     is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Lost item with cancelled hold has holding branch equallying the transfers source branch' );
+
+};
+
+subtest 'transferbook test' => sub {
+    plan tests => 5;
+
+    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $item = $builder->build_sample_item();
+    ok( $item->holdingbranch ne $library->branchcode && $item->homebranch ne $library->branchcode, "Item is not held or owned by library");
+    C4::Circulation::transferbook({
+        from_branch => $library->branchcode,
+        to_branch => $item->homebranch,
+        barcode   => $item->barcode,
+    });
+    my ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
+    is( $from_branch, $library->branchcode, 'The transfer is initiated from the specified branch, not the items home or holdingbranch');
+    is( $to_branch, $item->homebranch, 'The transfer is initiated to the specified branch');
+    C4::Circulation::transferbook({
+        from_branch => $item->homebranch,
+        to_branch => $library->branchcode,
+        barcode   => $item->barcode,
+    });
+    ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
+    is( $from_branch, $item->homebranch, 'The transfer is initiated from the specified branch');
+    is( $to_branch, $library->branchcode, 'The transfer is initiated to the specified branch');
+
 };
 
 subtest 'CanBookBeIssued | is_overdue' => sub {