Bug 24476: Allow patrons to opt out of auto-renewal
authorNick Clemens <nick@bywatersolutions.com>
Thu, 23 Jan 2020 02:38:50 +0000 (02:38 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 24 Mar 2020 11:23:47 +0000 (11:23 +0000)
To test:
1 - Verify on staff side that patron can be edited to opt in our out of auto renewal
2 - Check out some items to a patron opted in to auto renewal
3 - Ensure the items are checked out and set to autorenew
4 - Login on the opac at the patron
5 - Verify items cannot be renewed as scheduled for auto-renewal
6 - On staff side, opt patron out of auto renewal
7 - Verify on opac items are no longer marked for auto renewal
8 - Run the auto renewal cron job, items are not renewed
9 - Set 'no renewal before' to a setting that would prevent renewal
10 - Verify that opting patron in or out of auto renewal changes only the reason items cannot be renewed
11 - Set 'no renewal before' to a setting that would allow for renewal
12 - Verify that opting patron in/out changes their ability to renew
13 - Verify that when opted out cron does not renew
14 - Verify that when opted in the item is auto renewed
15 - Reset the due date, opt out, verify manual renewal succeeds

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Circulation.pm
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-brief.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
members/memberentry.pl
misc/cronjobs/automatic_renewals.pl
t/db_dependent/Circulation.t

index af2903c..30311b0 100644 (file)
@@ -2817,7 +2817,7 @@ sub CanBookBeRenewed {
 
         # Fallback for automatic renewals:
         # If norenewalbefore is undef, don't renew before due date.
-        if ( $issue->auto_renew && !$auto_renew ) {
+        if ( $issue->auto_renew && !$auto_renew && $patron->autorenew_checkouts ) {
             my $now = dt_from_string;
             if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
                 $auto_renew = 1;
index 3d13536..feb3c3a 100644 (file)
                                                         <div id="set-automatic-renewal" class="circ-setting">
                                                             [% IF NEEDSCONFIRMATION %]
                                                                 [% IF auto_renew %]
-                                                                    <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled" checked="checked" />
+                                                                    [% IF patron.autorenewal %]
+                                                                        <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled"
+                                                                        title="Patron has opted out of auto-renewal"/>
+                                                                    [% ELSE %]
+                                                                        <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled" checked="checked" />
+                                                                    [% END %]
                                                                 [% ELSE %]
                                                                     <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled" />
                                                                 [% END %]
                                                             [% ELSE %]
-                                                                [% IF auto_renew %]
+                                                                [% IF ( auto_renew && patron.autorenewal ) %]
                                                                     <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" class="circ_setting" checked="checked" />
-                                                                [% ELSE %]
+                                                                [% ELSIF patron.autorenewal %]
                                                                     <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" class="circ_setting" />
+                                                                [% ELSE %]
+                                                                    <input type="checkbox" name="auto_renew" id="auto_renew" value="auto_renew" disabled="disabled"
+                                                                    title="Patron has opted out of auto-renewal"/>
                                                                 [% END %]
                                                             [% END %]
 
index 2b6a379..20ddc76 100644 (file)
@@ -874,6 +874,33 @@ legend:hover {
                                             </li>
                                         [% END # /UNLESS nosort2 %]
 
+                                        [% UNLESS noautorenewal %]
+                                            <li class="radio">
+                                                <label for="yes-autorenewal">
+                                                    Allow auto-renewal of items:
+                                                </label>
+                                                    [% IF ( autorenewal ) %]
+                                                        <label for="yes-autorenewal">
+                                                            Yes
+                                                            <input type="radio" id="yes-autorenewal" name="autorenewal" value="1" checked="checked" />
+                                                        </label>
+                                                        <label for="no-autorenewal">
+                                                            No
+                                                            <input type="radio" id="no-autorenewal" name="autorenewal" value="0" />
+                                                        </label>
+                                                    [% ELSE %]
+                                                        <label for="yes-autorenewal">
+                                                            Yes
+                                                            <input type="radio" id="yes-autorenewal" name="autorenewal" value="1" />
+                                                        </label>
+                                                        <label for="no-autorenewal">
+                                                            No
+                                                            <input type="radio" id="no-autorenewal" name="autorenewal" value="0" checked="checked" />
+                                                        </label>
+                                                    [% END %]
+                                            </li>
+                                        [% END %]
+
                                         [% IF ( Koha.Preference('CheckPrevCheckout') == 'softyes' || Koha.Preference('CheckPrevCheckout') == 'softno' ) %]
                                             <li>
                                                 <label for="checkprevcheckout">Check for previous checkouts: </label>
index 77b3687..c16e432 100644 (file)
@@ -52,6 +52,7 @@
 [% CASE 'contacttitle'        %]<span>Contact: Title</span>
 [% CASE 'relationship'        %]<span>Contact: Relationship</span>
 [% CASE 'sex'                 %]<span>Gender</span>
+[% CASE 'autorenewal'         %]<span>Auto-renewal</span>
 [% CASE 'altcontactfirstname' %]<span>Alternate contact: First name</span>
 [% CASE 'altcontactsurname'   %]<span>Alternate contact: Surname</span>
 [% CASE 'altcontactaddress1'  %]<span>Alternate contact: Address</span>
index 1c3b2c3..ecac3b7 100644 (file)
@@ -84,6 +84,7 @@
             <li><span class="label">Library: </span>[% patron.library.branchname | html %]</li>
             [% IF ( patron.sort1 ) %]<li><span class="label">Sort field 1:</span>[% AuthorisedValues.GetByCode('Bsort1', patron.sort1) | html %]</li>[% END %]
             [% IF ( patron.sort2 ) %]<li><span class="label">Sort field 2:</span>[% AuthorisedValues.GetByCode('Bsort2', patron.sort2) | html %]</li>[% END %]
+            [% UNLESS ( patron.autorenewal ) %]<li>Auto renewal: Patron has opted out</li>[% END %]
         </ol>
     </div>
     </div>
index e309d79..488515b 100644 (file)
                                                 [% AuthorisedValues.GetByCode('Bsort2', patron.sort2) | html %]
                                             </li>
                                         [% END %]
+                                        [% UNLESS ( patron.autorenewal ) %]
+                                            <li id="patron-autorenewal">
+                                                <span class="label">Auto renewal:</span>
+                                                Patron has opted out
+                                            </li>
+                                        [% END %]
                                         <li id="patron-username">
                                             <span class="label">Username: </span>
                                             [% patron.userid | html %]
index 8761cc8..a2bcde4 100644 (file)
                                         [% END %]
                                     </li>
                                 [% END %]
+                                [% UNLESS hidden.defined('autorenewal') %]
+                                    <li class="lradio">
+                                        <label for="yes-autorenewal">
+                                            Allow auto-renewal:
+                                        </label>
+                                            [% IF ( borrower.autorenewal ) %]
+                                                <label class="radio inline" for="yes-autorenewal">
+                                                    Yes
+                                                    <input type="radio" id="yes-autorenewal" name="borrower_autorenewal" value="1" checked="checked" />
+                                                </label>
+
+                                                <label class="radio inline" for="no-autorenewal">
+                                                    No
+                                                    <input type="radio" id="no-autorenewal" name="borrower_autorenewal" value="0" />
+                                                </label>
+                                            [% ELSE %]
+                                                <label class="radio inline" for="yes-autorenewal">
+                                                    Yes
+                                                    <input type="radio" id="yes-autorenewal" name="borrower_autorenewal" value="1" />
+                                                </label>
+                                                <label class="radio inline" for="no-autorenewal">
+                                                    No
+                                                    <input type="radio" id="no-autorenewal" name="borrower_autorenewal" value="0" checked="checked" />
+                                                </label>
+                                            [% END %]
+                                    </li>
+                                [% END %]
                             </ol>
                         </fieldset>
                 [% END # / defined 'branchcode' %]
index 369dbd7..47f10db 100644 (file)
                                                     [% ELSIF ISSUE.auto_account_expired %]
                                                         Automatic renewal failed, your account is expired.
                                                         <span class="renewals">([% ISSUE.renewsleft | html %] of [% ISSUE.renewsallowed | html %] renewals remaining)</span>
-                                                    [% ELSIF ( ISSUE.auto_renew || ISSUE.auto_too_soon ) %]
-                                                        Automatic renewal
-                                                        <span class="renewals">([% ISSUE.renewsleft | html %] of [% ISSUE.renewsallowed | html %] renewals remaining)</span>
                                                     [% ELSIF ( ISSUE.too_soon ) %]
                                                         No renewal before [% ISSUE.soonestrenewdate | html %]
                                                         <span class="renewals">([% ISSUE.renewsleft | html %] of [% ISSUE.renewsallowed | html %] renewals remaining)</span>
+                                                    [% ELSIF ( ISSUE.auto_renew || ISSUE.auto_too_soon ) %]
+                                                        Automatic renewal
+                                                        <span class="renewals">([% ISSUE.renewsleft | html %] of [% ISSUE.renewsallowed | html %] renewals remaining)</span>
                                                     [% ELSIF ( ISSUE.item_denied_renewal ) %]
                                                         Renewal not allowed
                                                     [% END %]
index 052dbe2..ba47e1d 100755 (executable)
@@ -739,6 +739,7 @@ $template->param(no_add => $no_add);
 
 $template->param( sort1 => $data{'sort1'});
 $template->param( sort2 => $data{'sort2'});
+$template->param( autorenew => $data{'autorenew'});
 
 if ($nok) {
     foreach my $error (@errors) {
index d7bc5a1..a3bded3 100755 (executable)
@@ -80,7 +80,7 @@ GetOptions(
 pod2usage(0) if $help;
 cronlogaction();
 
-my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 });
+my $auto_renews = Koha::Checkouts->search({ auto_renew => 1, 'borrower.autorenewal' => 1 },{ join => 'borrower'});
 
 my %report;
 $verbose = 1 unless $verbose or $confirm;
index f0d46df..72dd1d2 100755 (executable)
@@ -274,7 +274,7 @@ Koha::CirculationRules->set_rules(
 
 my ( $reused_itemnumber_1, $reused_itemnumber_2 );
 subtest "CanBookBeRenewed tests" => sub {
-    plan tests => 77;
+    plan tests => 83;
 
     C4::Context->set_preference('ItemsDeniedRenewal','');
     # Generate test biblio