Bug 10067: decreaseLoanHighHolds messes with specify due date
authorEivin Giske Skaaren <eskaaren@yahoo.no>
Mon, 25 May 2015 17:10:54 +0000 (17:10 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 17 Nov 2015 13:02:35 +0000 (10:02 -0300)
To test:

1. On a branch up to date with master: apply the patch.

2. Try to check out items both with and without holds.
(The decreaseLoanHighHolds function should be configured and kick in when testing an item.

3. Expected results are:
The due date date field should be cleared after checkout if "Remember for session"
is not selected. If it is selected then the chosen date should stay in the field even
if the warning about reduced loan time for an item with too many holds is displayed.
Also the correct due dates are shown in the table after a checkout.

Known limitation: Does not work too well when jumping between different parts
of the system as it relies on the values sent to the circulation.pl script.

Sponsored-by: Halland County Library
Refactored to both fix specific issue where date is changed
and still have the old behaviour with date kept intact.

Rebase
Remove code whitespace cleanup

Remove one more code whitespace cleanup

Removed duplicate tag

Refactored stickyduedate session parameter

Fix datefield set by highholds if blanc

Signed-off-by: Nicole Engard <nengard@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
circ/circulation.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt

index c8e7872..f16475e 100755 (executable)
@@ -55,7 +55,6 @@ use Date::Calc qw(
 );
 use List::MoreUtils qw/uniq/;
 
-
 #
 # PARAMETERS READING
 #
@@ -156,7 +155,6 @@ $findborrower =~ s|,| |g;
 $branch  = C4::Context->userenv->{'branch'};  
 $printer = C4::Context->userenv->{'branchprinter'};
 
-
 # If AutoLocation is not activated, we show the Circulation Parameters to chage settings of librarian
 if (C4::Context->preference("AutoLocation") != 1) {
     $template->param(ManualLocation => 1);
@@ -176,7 +174,10 @@ my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickydu
 my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
 $duedatespec = eval { output_pref( { dt => dt_from_string( $duedatespec ), dateformat => 'iso' }); }
     if ( $duedatespec );
-
+my $restoreduedatespec  = $query->param('restoreduedatespec') || $session->param('stickyduedate') || $duedatespec;
+if ($restoreduedatespec eq "highholds_empty") {
+    undef $restoreduedatespec;
+}
 my $issueconfirmed = $query->param('issueconfirmed');
 my $cancelreserve  = $query->param('cancelreserve');
 my $print          = $query->param('print') || q{};
@@ -577,6 +578,17 @@ my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{stree
 
 $template->param(%$borrower);
 
+# Restore date if changed by holds and/or save stickyduedate to session
+if ($restoreduedatespec || $stickyduedate) {
+    $duedatespec = $restoreduedatespec || $duedatespec;
+
+    if ($stickyduedate) {
+        $session->param( 'stickyduedate', $duedatespec );
+    }
+} elsif (defined($duedatespec) && !defined($restoreduedatespec)) {
+    undef $duedatespec;
+}
+
 $template->param(
     lib_messages_loop => $lib_messages_loop,
     bor_messages_loop => $bor_messages_loop,
@@ -595,6 +607,7 @@ $template->param(
     barcodes          => $barcodes,
     stickyduedate     => $stickyduedate,
     duedatespec       => $duedatespec,
+    restoreduedatespec => $restoreduedatespec,
     message           => $message,
     totaldue          => sprintf('%.2f', $total),
     inprocess         => $inprocess,
@@ -612,11 +625,6 @@ $template->param(
     relatives_borrowernumbers => \@relatives,
 );
 
-# save stickyduedate to session
-if ($stickyduedate) {
-    $session->param( 'stickyduedate', $duedatespec );
-}
-
 my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
 $template->param( picture => 1 ) if $picture;
 
index 07ef6ce..19ba9fa 100644 (file)
@@ -315,13 +315,19 @@ $(document).ready(function() {
 [% IF HIGHHOLDS %]
        <script language="JavaScript" type="text/javascript">
        $(document).ready(function() {
-               $("input[name=duedatespec]:hidden").val('[% HIGHHOLDS.returndate %]');
+            $("input[name=duedatespec]:hidden").val('[% HIGHHOLDS.returndate %]');
+            if ('[% duedatespec %]' === '') {
+                $("input[name=restoreduedatespec]:hidden").val('highholds_empty');
+            } else {
+                $("input[name=restoreduedatespec]:hidden").val('[% duedatespec %]');
+            }
        });
        </script>
 [% END %]
 
 [% IF CAN_user_circulate_force_checkout or HIGHHOLDS %]
 <form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
+    <input type="hidden" name="restoreduedatespec" />
 
 [% IF (forceallow) %]<input type="hidden" name="forceallow" value="1">[% END %]
 
@@ -366,6 +372,7 @@ $(document).ready(function() {
 
 [% IF ( RESERVED ) %]
 <form method="get" action="/cgi-bin/koha/circ/circulation.pl">
+    <input type="hidden" name="restoreduedatespec" />
     <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
     <input type="hidden" name="duedatespec" value="[% duedatespec %]" />
     <input type="hidden" name="stickyduedate" value="[% stickyduedate %]" />
@@ -375,6 +382,7 @@ $(document).ready(function() {
 
 [% IF ( RESERVE_WAITING ) %]
 <form method="get" action="/cgi-bin/koha/circ/circulation.pl">
+    <input type="hidden" name="restoreduedatespec" />
     <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
     <input type="hidden" name="duedatespec" value="[% duedatespec %]" />
     <input type="hidden" name="stickyduedate" value="[% stickyduedate %]" />
@@ -386,6 +394,7 @@ $(document).ready(function() {
     [% IF (forceallow) %]<input type="hidden" name="forceallow" value="1">[% END %]
     <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
     <input type="hidden" name="duedatespec" value="[% duedatespec %]" />
+    <input type="hidden" name="restoreduedatespec" />
     <input type="hidden" name="stickyduedate" value="[% stickyduedate %]" />
     [% IF CAN_user_circulate_force_checkout or HIGHHOLDS %]
         [% IF ( RENEW_ISSUE ) %]
@@ -430,6 +439,7 @@ $(document).ready(function() {
                     <br />
                     <form method="post" action="/cgi-bin/koha/circ/circulation.pl" autocomplete="off">
                     [% IF (forceallow) %]<input type="hidden" name="forceallow" value="1">[% END %]
+                        <input type="hidden" name="restoreduedatespec" />
                         <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
                         <input type="hidden" name="duedatespec" value="[% duedatespec %]" />
                         <input type="hidden" name="stickyduedate" value="[% stickyduedate %]" />
@@ -538,11 +548,11 @@ No patron matched <span class="ex">[% message %]</span>
 </h4>
 [% END %]
 
-
 [% IF ( borrowers ) %]
 [% INCLUDE 'patron-toolbar.inc' %]
 
 <form method="post" action="/cgi-bin/koha/circ/circulation.pl" id="mainform" name="mainform" autocomplete="off">
+    <input type="hidden" name="restoreduedatespec" />
 <fieldset id="circ_circulation_selectborrower" class="brief">
     <legend>Patron selection</legend>
 
@@ -598,8 +608,8 @@ No patron matched <span class="ex">[% message %]</span>
 
 [% END %]
 
-
 <form method="post" action="/cgi-bin/koha/circ/circulation.pl" id="mainform" name="mainform" autocomplete="off">
+    <input type="hidden" name="restoreduedatespec" />
 [% IF ( issue ) %]
     <fieldset id="circ_circulation_issue" class="lastchecked">
 [% ELSE %]
@@ -784,8 +794,6 @@ No patron matched <span class="ex">[% message %]</span>
             </li>
                        [% END %]
 
-
-
                        </ul>
         </div>
 
@@ -853,7 +861,6 @@ No patron matched <span class="ex">[% message %]</span>
      <!-- /If flagged -->[% END %]
 
        
-
 </div>
 </div>
 
@@ -969,8 +976,6 @@ No patron matched <span class="ex">[% message %]</span>
 </div></div>
 [% END %]
 
-
-
 </div>
 </div>
 [% UNLESS ( borrowers ) %][% IF ( borrowernumber ) %]<div class="yui-b">