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

(-)a/C4/Circulation.pm (-1 / +17 lines)
Lines 2984-2989 sub CanBookBeRenewed { Link Here
2984
        return ( 0, 'overdue');
2984
        return ( 0, 'overdue');
2985
    }
2985
    }
2986
2986
2987
    if ( $itemissue->{auto_renew}
2988
        and defined $issuingrule->{no_auto_renewal_after}
2989
                and $issuingrule->{no_auto_renewal_after} ne "" ) {
2990
2991
        # Get issue_date and add no_auto_renewal_after
2992
        # If this is greater than today, it's too late for renewal.
2993
        my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
2994
        $maximum_renewal_date->add(
2995
            $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
2996
        );
2997
        my $now = dt_from_string;
2998
        if ( $now >= $maximum_renewal_date ) {
2999
            return ( 0, "auto_too_late" );
3000
        }
3001
    }
3002
2987
    if ( defined $issuingrule->{norenewalbefore}
3003
    if ( defined $issuingrule->{norenewalbefore}
2988
        and $issuingrule->{norenewalbefore} ne "" )
3004
        and $issuingrule->{norenewalbefore} ne "" )
2989
    {
3005
    {
Lines 3013-3019 sub CanBookBeRenewed { Link Here
3013
3029
3014
    # Fallback for automatic renewals:
3030
    # Fallback for automatic renewals:
3015
    # If norenewalbefore is undef, don't renew before due date.
3031
    # If norenewalbefore is undef, don't renew before due date.
3016
    elsif ( $itemissue->{auto_renew} ) {
3032
    if ( $itemissue->{auto_renew} ) {
3017
        my $now = dt_from_string;
3033
        my $now = dt_from_string;
3018
        return ( 0, "auto_renew" )
3034
        return ( 0, "auto_renew" )
3019
          if $now >= $itemissue->{date_due};
3035
          if $now >= $itemissue->{date_due};
(-)a/admin/smart-rules.pl (+3 lines)
Lines 136-141 elsif ($op eq 'add') { Link Here
136
    my $norenewalbefore  = $input->param('norenewalbefore');
136
    my $norenewalbefore  = $input->param('norenewalbefore');
137
    $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
137
    $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
138
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
138
    my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
139
    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
140
    $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
139
    my $reservesallowed  = $input->param('reservesallowed');
141
    my $reservesallowed  = $input->param('reservesallowed');
140
    my $onshelfholds     = $input->param('onshelfholds') || 0;
142
    my $onshelfholds     = $input->param('onshelfholds') || 0;
141
    $maxissueqty =~ s/\s//g;
143
    $maxissueqty =~ s/\s//g;
Lines 171-176 elsif ($op eq 'add') { Link Here
171
        renewalperiod                 => $renewalperiod,
173
        renewalperiod                 => $renewalperiod,
172
        norenewalbefore               => $norenewalbefore,
174
        norenewalbefore               => $norenewalbefore,
173
        auto_renew                    => $auto_renew,
175
        auto_renew                    => $auto_renew,
176
        no_auto_renewal_after         => $no_auto_renewal_after,
174
        reservesallowed               => $reservesallowed,
177
        reservesallowed               => $reservesallowed,
175
        issuelength                   => $issuelength,
178
        issuelength                   => $issuelength,
176
        lengthunit                    => $lengthunit,
179
        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 858-863 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
858
  `renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit
858
  `renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit
859
  `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date.
859
  `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date.
860
  `auto_renew` BOOLEAN default FALSE, -- automatic renewal
860
  `auto_renew` BOOLEAN default FALSE, -- automatic renewal
861
  `no_auto_renewal_after` int(4) default NULL, -- no auto renewal allowed after X days or hours after the issue date
861
  `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
862
  `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
862
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
863
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
863
  overduefinescap decimal(28,6) default NULL, -- the maximum amount of an overdue fine
864
  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 176-181 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
176
                <th>Renewal period</th>
176
                <th>Renewal period</th>
177
                <th>No renewal before</th>
177
                <th>No renewal before</th>
178
                <th>Automatic renewal</th>
178
                <th>Automatic renewal</th>
179
                <th>No automatic renewal after</th>
179
                <th>Holds allowed (count)</th>
180
                <th>Holds allowed (count)</th>
180
                <th>On shelf holds allowed</th>
181
                <th>On shelf holds allowed</th>
181
                <th>Item level holds</th>
182
                <th>Item level holds</th>
Lines 254-259 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
254
                                No
255
                                No
255
                                [% END %]
256
                                [% END %]
256
                            </td>
257
                            </td>
258
                            <td>[% rule.no_auto_renewal_after %]</td>
257
							<td>[% rule.reservesallowed %]</td>
259
							<td>[% rule.reservesallowed %]</td>
258
                                                        <td>
260
                                                        <td>
259
                                                            [% IF rule.onshelfholds == 1 %]
261
                                                            [% IF rule.onshelfholds == 1 %]
Lines 328-333 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
328
                            <option value="yes">Yes</option>
330
                            <option value="yes">Yes</option>
329
                        </select>
331
                        </select>
330
                    </td>
332
                    </td>
333
                    <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
331
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
334
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
332
                    <td>
335
                    <td>
333
                        <select name="onshelfholds" id="onshelfholds">
336
                        <select name="onshelfholds" id="onshelfholds">
Lines 371-376 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
371
                      <th>Renewal period</th>
374
                      <th>Renewal period</th>
372
                      <th>No renewal before</th>
375
                      <th>No renewal before</th>
373
                      <th>Automatic renewal</th>
376
                      <th>Automatic renewal</th>
377
                      <th>No automatic renewal after</th>
374
                      <th>Holds allowed (count)</th>
378
                      <th>Holds allowed (count)</th>
375
                      <th>On shelf holds allowed</th>
379
                      <th>On shelf holds allowed</th>
376
                      <th>Item level holds</th>
380
                      <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 30-36 use Koha::Database; Link Here
30
30
31
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
32
32
33
use Test::More tests => 86;
33
use Test::More tests => 87;
34
34
35
BEGIN {
35
BEGIN {
36
    use_ok('C4::Circulation');
36
    use_ok('C4::Circulation');
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