View | Details | Raw Unified | Return to bug 15581
Collapse All | Expand All

(-)a/C4/Circulation.pm (-1 / +17 lines)
Lines 2888-2893 sub CanBookBeRenewed { Link Here
2888
        return ( 0, 'overdue');
2888
        return ( 0, 'overdue');
2889
    }
2889
    }
2890
2890
2891
    if ( $itemissue->{auto_renew}
2892
        and defined $issuingrule->{no_auto_renewal_after}
2893
                and $issuingrule->{no_auto_renewal_after} ne "" ) {
2894
2895
        # Get issue_date and add no_auto_renewal_after
2896
        # If this is greater than today, it's too late for renewal.
2897
        my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
2898
        $maximum_renewal_date->add(
2899
            $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
2900
        );
2901
        my $now = dt_from_string;
2902
        if ( $now >= $maximum_renewal_date ) {
2903
            return ( 0, "auto_too_late" );
2904
        }
2905
    }
2906
2891
    if ( defined $issuingrule->{norenewalbefore}
2907
    if ( defined $issuingrule->{norenewalbefore}
2892
        and $issuingrule->{norenewalbefore} ne "" )
2908
        and $issuingrule->{norenewalbefore} ne "" )
2893
    {
2909
    {
Lines 2917-2923 sub CanBookBeRenewed { Link Here
2917
2933
2918
    # Fallback for automatic renewals:
2934
    # Fallback for automatic renewals:
2919
    # If norenewalbefore is undef, don't renew before due date.
2935
    # If norenewalbefore is undef, don't renew before due date.
2920
    elsif ( $itemissue->{auto_renew} ) {
2936
    if ( $itemissue->{auto_renew} ) {
2921
        my $now = dt_from_string;
2937
        my $now = dt_from_string;
2922
        return ( 0, "auto_renew" )
2938
        return ( 0, "auto_renew" )
2923
          if $now >= $itemissue->{date_due};
2939
          if $now >= $itemissue->{date_due};
(-)a/admin/smart-rules.pl (+3 lines)
Lines 133-138 elsif ($op eq 'add') { Link Here
133
    my $norenewalbefore  = $input->param('norenewalbefore');
133
    my $norenewalbefore  = $input->param('norenewalbefore');
134
    $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
134
    $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
135
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
135
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
136
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
137
    $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
136
    my $reservesallowed  = $input->param('reservesallowed');
138
    my $reservesallowed  = $input->param('reservesallowed');
137
    my $onshelfholds     = $input->param('onshelfholds') || 0;
139
    my $onshelfholds     = $input->param('onshelfholds') || 0;
138
    $maxissueqty =~ s/\s//g;
140
    $maxissueqty =~ s/\s//g;
Lines 168-173 elsif ($op eq 'add') { Link Here
168
        renewalperiod                 => $renewalperiod,
170
        renewalperiod                 => $renewalperiod,
169
        norenewalbefore               => $norenewalbefore,
171
        norenewalbefore               => $norenewalbefore,
170
        auto_renew                    => $auto_renew,
172
        auto_renew                    => $auto_renew,
173
        no_auto_renewal_after         => $no_auto_renewal_after,
171
        reservesallowed               => $reservesallowed,
174
        reservesallowed               => $reservesallowed,
172
        issuelength                   => $issuelength,
175
        issuelength                   => $issuelength,
173
        lengthunit                    => $lengthunit,
176
        lengthunit                    => $lengthunit,
(-)a/installer/data/mysql/atomicupdate/bug_15581.sql (+1 lines)
Line 0 Link Here
1
ALTER TABLE issuingrules ADD COLUMN no_auto_renewal_after INT(4) DEFAULT NULL AFTER auto_renew;
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1206-1211 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
1206
  `renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit
1206
  `renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit
1207
  `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date.
1207
  `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date.
1208
  `auto_renew` BOOLEAN default FALSE, -- automatic renewal
1208
  `auto_renew` BOOLEAN default FALSE, -- automatic renewal
1209
  `no_auto_renewal_after` int(4) default NULL, -- no auto renewal allowed after X days or hours after the issue date
1209
  `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
1210
  `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
1210
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
1211
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
1211
  overduefinescap decimal(28,6) default NULL, -- the maximum amount of an overdue fine
1212
  overduefinescap decimal(28,6) default NULL, -- the maximum amount of an overdue fine
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+4 lines)
Lines 169-174 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
169
                <th>Renewal period</th>
169
                <th>Renewal period</th>
170
                <th>No renewal before</th>
170
                <th>No renewal before</th>
171
                <th>Automatic renewal</th>
171
                <th>Automatic renewal</th>
172
                <th>No automatic renewal after</th>
172
                <th>Holds allowed (count)</th>
173
                <th>Holds allowed (count)</th>
173
                <th>On shelf holds allowed</th>
174
                <th>On shelf holds allowed</th>
174
                <th>Item level holds</th>
175
                <th>Item level holds</th>
Lines 247-252 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
247
                                No
248
                                No
248
                                [% END %]
249
                                [% END %]
249
                            </td>
250
                            </td>
251
                            <td>[% rule.no_auto_renewal_after %]</td>
250
							<td>[% rule.reservesallowed %]</td>
252
							<td>[% rule.reservesallowed %]</td>
251
                                                        <td>[% IF rule.onshelfholds %]Yes[% ELSE %]No[% END %]</td>
253
                                                        <td>[% IF rule.onshelfholds %]Yes[% ELSE %]No[% END %]</td>
252
                                                        <td>[% IF rule.opacitemholds == 'F'%]Force[% ELSIF rule.opacitemholds == 'Y'%]Allow[% ELSE %]Don't allow[% END %]</td>
254
                                                        <td>[% IF rule.opacitemholds == 'F'%]Force[% ELSIF rule.opacitemholds == 'Y'%]Allow[% ELSE %]Don't allow[% END %]</td>
Lines 314-319 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
314
                            <option value="yes">Yes</option>
316
                            <option value="yes">Yes</option>
315
                        </select>
317
                        </select>
316
                    </td>
318
                    </td>
319
                    <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
317
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
320
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
318
                    <td>
321
                    <td>
319
                        <select name="onshelfholds" id="onshelfholds">
322
                        <select name="onshelfholds" id="onshelfholds">
Lines 356-361 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
356
                      <th>Renewal period</th>
359
                      <th>Renewal period</th>
357
                      <th>No renewal before</th>
360
                      <th>No renewal before</th>
358
                      <th>Automatic renewal</th>
361
                      <th>Automatic renewal</th>
362
                      <th>No automatic renewal after</th>
359
                      <th>Holds allowed (count)</th>
363
                      <th>Holds allowed (count)</th>
360
                      <th>On shelf holds allowed</th>
364
                      <th>On shelf holds allowed</th>
361
                      <th>Item level holds</th>
365
                      <th>Item level holds</th>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt (+12 lines)
Lines 77-82 Link Here
77
                                    </form>
77
                                    </form>
78
                                [% END %]
78
                                [% END %]
79
79
80
                            [% ELSIF error == "auto_too_late" %]
81
82
                                <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal and cannot be renewed since [% latestrenewdate | $KohaDates %]. </p>
83
84
                                [% IF Koha.Preference('AllowRenewalLimitOverride') %]
85
                                    <form method="post" action="/cgi-bin/koha/circ/renew.pl">
86
                                        <input type="hidden" name="barcode" value="[% item.barcode %]"/>
87
                                        <input type="hidden" name="override_limit" value="1" />
88
                                        <input type="submit" class="approve" value="Override and renew" />
89
                                    </form>
90
                                [% END %]
91
80
                            [% ELSIF error == "auto_renew" %]
92
                            [% ELSIF error == "auto_renew" %]
81
93
82
                                <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal. </p>
94
                                <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal. </p>
(-)a/t/db_dependent/Circulation.t (-1 / +41 lines)
Lines 532-537 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
532
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
532
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
533
    );
533
    );
534
534
535
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
536
        plan tests => 8;
537
        my $item_to_auto_renew = $builder->build(
538
            {   source => 'Item',
539
                value  => {
540
                    biblionumber  => $biblionumber,
541
                    homebranch    => $branch,
542
                    holdingbranch => $branch,
543
                }
544
            }
545
        );
546
547
        my $ten_days_before = dt_from_string->add( days => -10 );
548
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
549
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
550
551
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 9');
552
        ( $renewokay, $error ) =
553
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
554
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
555
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
556
557
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 10');
558
        ( $renewokay, $error ) =
559
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
560
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
561
        is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
562
563
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 11');
564
        ( $renewokay, $error ) =
565
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
566
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
567
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
568
569
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
570
        ( $renewokay, $error ) =
571
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
572
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
573
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
574
    };
575
535
    # Too many renewals
576
    # Too many renewals
536
577
537
    # set policy to forbid renewals
578
    # set policy to forbid renewals
538
- 

Return to bug 15581