Bug 24612: Make hold-transfer-slip take reserve_id
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 12 Feb 2020 09:02:56 +0000 (10:02 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 22 May 2020 08:33:16 +0000 (09:33 +0100)
To make sure we are going to display the correct hold's info we need to
pass the reserve_id.

== Test plan ==
1. Add some content to HOLD_SLIP notice, e.g.

  <h2>[% branch.branchname %]</h2>
  <div>[% biblio.author %]<br>[% biblio.title %]<br>[% item.barcode %]
  <ul><li> Reserve ID:  [% hold.reserve_id %]</li>
  <li>Expiration date: [% hold.expirationdate %]</li></ul>

2. Add 2 holds for 1 patron to a single record
3. Check the reserve IDs in the reserves table - on a clean sandbox, they will be 1 and 2
4. Check in one of the items from the record and print the slip
5. Note that the reserve ID on the slip is 2 and the expiration date is blank
6. Repeated check ins do not change this
7. Check in a second item from the record
8. Note that the reserve ID for this hold is also 2, but this time the expiration date is filled in
9. Check in the first item again - the reserve ID stays as 2, but this time the expiration date is filled in
10. Apply patch
11. cancel the holds to come back to a clean state
    (and maybe ensure items aren't in transit)
12. redo the test and see the following differences
13. 1st checkin:
    1. expiration date ok
    2. the reserve ID is the one of the first hold
14. 2nd checkin:
    1. expiration date ok
    2. the reserve ID is the one of the second hold

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Circulation.pm
C4/Reserves.pm
circ/circulation.pl
circ/hold-transfer-slip.pl
circ/returns.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt

index e439250..2e40721 100644 (file)
@@ -1038,6 +1038,7 @@ sub CanBookBeIssued {
                     $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
                     $needsconfirmation{'resbranchcode'} = $res->{branchcode};
                     $needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'};
+                    $needsconfirmation{'reserve_id'} = $res->{reserve_id};
                 }
                 elsif ( $restype eq "Reserved" ) {
                     # The item is on reserve for someone else.
@@ -1048,6 +1049,7 @@ sub CanBookBeIssued {
                     $needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
                     $needsconfirmation{'resbranchcode'} = $patron->branchcode;
                     $needsconfirmation{'resreservedate'} = $res->{reservedate};
+                    $needsconfirmation{'reserve_id'} = $res->{reserve_id};
                 }
             }
         }
index 9f8d316..d328773 100644 (file)
@@ -604,7 +604,7 @@ sub GetOtherReserves {
             ModReserveStatus($itemnumber,'W');
         }
 
-        $nextreservinfo = $checkreserves->{'borrowernumber'};
+        $nextreservinfo = $checkreserves;
     }
 
     return ( $messages, $nextreservinfo );
@@ -1191,7 +1191,7 @@ sub ModReserveCancelAll {
     #step 2 launch the subroutine of the others reserves
     ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
 
-    return ( $messages, $nextreservinfo );
+    return ( $messages, $nextreservinfo->{borrowernumber} );
 }
 
 =head2 ModReserveMinusPriority
@@ -2055,36 +2055,12 @@ available within the slip:
 sub ReserveSlip {
     my ($args) = @_;
     my $branchcode     = $args->{branchcode};
-    my $borrowernumber = $args->{borrowernumber};
-    my $biblionumber   = $args->{biblionumber};
-    my $itemnumber     = $args->{itemnumber};
-    my $barcode        = $args->{barcode};
-
-
-    my $patron = Koha::Patrons->find($borrowernumber);
-
-    my $hold;
-    if ($itemnumber || $barcode ) {
-        $itemnumber ||= Koha::Items->find( { barcode => $barcode } )->itemnumber;
-
-        $hold = Koha::Holds->search(
-            {
-                biblionumber   => $biblionumber,
-                borrowernumber => $borrowernumber,
-                itemnumber     => $itemnumber
-            }
-        )->next;
-    }
-    else {
-        $hold = Koha::Holds->search(
-            {
-                biblionumber   => $biblionumber,
-                borrowernumber => $borrowernumber
-            }
-        )->next;
-    }
+    my $reserve_id = $args->{reserve_id};
 
+    my $hold = Koha::Holds->find($reserve_id);
     return unless $hold;
+
+    my $patron = $hold->borrower;
     my $reserve = $hold->unblessed;
 
     return  C4::Letters::GetPreparedLetter (
index 81c3bcd..5ec80c8 100755 (executable)
@@ -419,7 +419,8 @@ if (@$barcodes) {
 
     if ($question->{RESERVE_WAITING} or $question->{RESERVED}){
         $template->param(
-            reserveborrowernumber => $question->{'resborrowernumber'}
+            reserveborrowernumber => $question->{'resborrowernumber'},
+            reserve_id => $question->{reserve_id},
         );
     }
 
index 328f481..a0cb0ef 100755 (executable)
@@ -35,10 +35,7 @@ my $input = new CGI;
 my $sessionID = $input->cookie("CGISESSID");
 my $session = get_session($sessionID);
 
-my $biblionumber = $input->param('biblionumber');
-my $borrowernumber = $input->param('borrowernumber');
-my $itemnumber = $input->param('itemnumber');
-my $barcode = $input->param('barcode');
+my $reserve_id = $input->param('reserve_id');
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
@@ -55,10 +52,7 @@ my $userenv = C4::Context->userenv;
 my ($slip, $is_html);
 if ( my $letter = ReserveSlip ({
     branchcode     => $session->param('branch') || $userenv->{branch},
-    borrowernumber => $borrowernumber,
-    biblionumber   => $biblionumber,
-    itemnumber     => $itemnumber,
-    barcode        => $barcode,
+    reserve_id => $reserve_id,
 }) ) {
     $slip = $letter->{content};
     $is_html = $letter->{is_html};
index 8044262..e1bce3c 100755 (executable)
@@ -77,9 +77,7 @@ my $session = get_session($sessionID);
 if ( $query->param('print_slip') ) {
     $template->param(
         print_slip     => 1,
-        borrowernumber => scalar $query->param('borrowernumber'), # FIXME We should send a Koha::Patron and raise an error if not exist.
-        biblionumber   => scalar $query->param('biblionumber'),
-        itemnumber     => scalar $query->param('itemnumber'),
+        reserve_id => scalar $query->param('reserve_id'),
     );
 }
 
@@ -419,15 +417,10 @@ if ( $messages->{'ResFound'}) {
         my $diffBranchSend = !$branchCheck ? $reserve->{branchcode} : undef;
         ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber}, $diffBranchSend, $reserve->{reserve_id} );
         my ( $messages, $nextreservinfo ) = GetOtherReserves($reserve->{itemnumber});
-
-        my $patron = Koha::Patrons->find( $nextreservinfo );
-
         $template->param(
             hold_auto_filled => 1,
             print_slip       => C4::Context->preference('HoldsAutoFillPrintSlip'),
-            patron           => $patron,
-            borrowernumber   => $patron->id,
-            biblionumber     => $biblio->id,
+            reserve_id       => $nextreservinfo->{reserve_id},
         );
 
         if ( $messages->{'transfert'} ) {
index b8ec599..e9534ea 100644 (file)
                                     <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
                                     <input type="hidden" name="duedatespec" value="[% duedatespec | html %]" />
                                     <input type="hidden" name="stickyduedate" value="[% stickyduedate | html %]" />
-                                    <button class="print" type="submit" onclick="Dopop('hold-transfer-slip.pl?borrowernumber=[% reserveborrowernumber | uri %]&amp;biblionumber=[% itembiblionumber | uri %]&amp;itemnumber=[% item.itemnumber | uri %]&amp;op=slip');this.form.submit();"><i class="fa fa-print"></i> Don't check out and print slip (P)</button>
+                                    <button class="print" type="submit" onclick="Dopop('hold-transfer-slip.pl?reserve_id=[% reserve_id | uri %]');this.form.submit();"><i class="fa fa-print"></i> Don't check out and print slip (P)</button>
                                 </form>
                             [% END %]
 
                                     <input type="hidden" name="borrowernumber" value="[% patron.borrowernumber | html %]" />
                                     <input type="hidden" name="duedatespec" value="[% duedatespec | html %]" />
                                     <input type="hidden" name="stickyduedate" value="[% stickyduedate | html %]" />
-                                    <button class="print" type="submit" onclick="Dopop('hold-transfer-slip.pl?borrowernumber=[% reserveborrowernumber | uri %]&amp;biblionumber=[% itembiblionumber | uri %]&amp;itemnumber=[% item.itemnumber | uri %]&amp;op=slip');this.form.submit();"><i class="fa fa-print"></i> Don't check out and print slip (P)</button>
+                                    <button class="print" type="submit" onclick="Dopop('hold-transfer-slip.pl?reserve_id=[% reserve_id | uri %]');this.form.submit();"><i class="fa fa-print"></i> Don't check out and print slip (P)</button>
                                 </form>
                             [% END %]
 
index bcde1e9..43515da 100644 (file)
 
             $(".print-slip").on('click', function(e) {
                 e.preventDefault();
-                Dopop('hold-transfer-slip.pl?borrowernumber=[% patron.borrowernumber | uri %]&amp;biblionumber=[% biblionumber | uri %]');
+                Dopop('hold-transfer-slip.pl?reserve_id=[% reserve_id | uri %]');
             });
 
             [% IF print_slip %]
-                Dopop('hold-transfer-slip.pl?borrowernumber=[% borrowernumber | uri %]&amp;biblionumber=[% biblionumber | uri %]&amp;itemnumber=[% itemnumber | uri %]');
+                Dopop('hold-transfer-slip.pl?reserve_id=[% reserve_id | uri %]');
             [% END %]
 
             var columns_settings = [% ColumnsSettings.GetColumns( 'circ', 'returns', 'checkedintable', 'json' ) | $raw %]