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

(-)a/C4/Circulation.pm (-1 / +17 lines)
Lines 2825-2830 sub CanBookBeRenewed { Link Here
2825
        return ( 0, 'overdue');
2825
        return ( 0, 'overdue');
2826
    }
2826
    }
2827
2827
2828
    if ( $itemissue->{auto_renew}
2829
        and defined $issuingrule->{no_auto_renewal_after}
2830
                and $issuingrule->{no_auto_renewal_after} ne "" ) {
2831
2832
        # Get issue_date and add no_auto_renewal_after
2833
        # If this is greater than today, it's too late for renewal.
2834
        my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
2835
        $maximum_renewal_date->add(
2836
            $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
2837
        );
2838
        my $now = dt_from_string;
2839
        if ( $now >= $maximum_renewal_date ) {
2840
            return ( 0, "auto_too_late" );
2841
        }
2842
    }
2843
2828
    if ( defined $issuingrule->{norenewalbefore}
2844
    if ( defined $issuingrule->{norenewalbefore}
2829
        and $issuingrule->{norenewalbefore} ne "" )
2845
        and $issuingrule->{norenewalbefore} ne "" )
2830
    {
2846
    {
Lines 2848-2854 sub CanBookBeRenewed { Link Here
2848
2864
2849
    # Fallback for automatic renewals:
2865
    # Fallback for automatic renewals:
2850
    # If norenewalbefore is undef, don't renew before due date.
2866
    # If norenewalbefore is undef, don't renew before due date.
2851
    elsif ( $itemissue->{auto_renew} ) {
2867
    if ( $itemissue->{auto_renew} ) {
2852
        my $now = dt_from_string;
2868
        my $now = dt_from_string;
2853
        return ( 0, "auto_renew" )
2869
        return ( 0, "auto_renew" )
2854
          if $now >= $itemissue->{date_due};
2870
          if $now >= $itemissue->{date_due};
(-)a/admin/smart-rules.pl (+3 lines)
Lines 132-137 elsif ($op eq 'add') { Link Here
132
    my $norenewalbefore  = $input->param('norenewalbefore');
132
    my $norenewalbefore  = $input->param('norenewalbefore');
133
    $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
133
    $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
134
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
134
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
135
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
136
    $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
135
    my $reservesallowed  = $input->param('reservesallowed');
137
    my $reservesallowed  = $input->param('reservesallowed');
136
    my $onshelfholds     = $input->param('onshelfholds') || 0;
138
    my $onshelfholds     = $input->param('onshelfholds') || 0;
137
    $maxissueqty =~ s/\s//g;
139
    $maxissueqty =~ s/\s//g;
Lines 166-171 elsif ($op eq 'add') { Link Here
166
        renewalperiod                 => $renewalperiod,
168
        renewalperiod                 => $renewalperiod,
167
        norenewalbefore               => $norenewalbefore,
169
        norenewalbefore               => $norenewalbefore,
168
        auto_renew                    => $auto_renew,
170
        auto_renew                    => $auto_renew,
171
        no_auto_renewal_after         => $no_auto_renewal_after,
169
        reservesallowed               => $reservesallowed,
172
        reservesallowed               => $reservesallowed,
170
        issuelength                   => $issuelength,
173
        issuelength                   => $issuelength,
171
        lengthunit                    => $lengthunit,
174
        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/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 (-2 / +42 lines)
Lines 29-35 use Koha::Database; Link Here
29
29
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
31
31
32
use Test::More tests => 82;
32
use Test::More tests => 83;
33
33
34
BEGIN {
34
BEGIN {
35
    use_ok('C4::Circulation');
35
    use_ok('C4::Circulation');
Lines 514-519 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
514
'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
514
'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
515
    );
515
    );
516
516
517
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
518
        plan tests => 8;
519
        my $item_to_auto_renew = $builder->build(
520
            {   source => 'Item',
521
                value  => {
522
                    biblionumber  => $biblionumber,
523
                    homebranch    => $branch,
524
                    holdingbranch => $branch,
525
                }
526
            }
527
        );
528
529
        my $ten_days_before = dt_from_string->add( days => -10 );
530
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
531
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
532
533
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 9');
534
        ( $renewokay, $error ) =
535
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
536
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
537
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
538
539
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 10');
540
        ( $renewokay, $error ) =
541
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
542
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
543
        is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
544
545
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 11');
546
        ( $renewokay, $error ) =
547
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
548
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
549
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_late)' );
550
551
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
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_renew', 'Cannot renew, renew is automatic' );
556
    };
557
517
    # Too many renewals
558
    # Too many renewals
518
559
519
    # set policy to forbid renewals
560
    # set policy to forbid renewals
520
- 

Return to bug 15581