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

(-)a/C4/Circulation.pm (-1 / +17 lines)
Lines 2853-2858 sub CanBookBeRenewed { Link Here
2853
        return ( 0, 'overdue');
2853
        return ( 0, 'overdue');
2854
    }
2854
    }
2855
2855
2856
    if ( $itemissue->{auto_renew}
2857
        and defined $issuingrule->{no_auto_renewal_after}
2858
                and $issuingrule->{no_auto_renewal_after} ne "" ) {
2859
2860
        # Get issue_date and add no_auto_renewal_after
2861
        # If this is greater than today, it's too late for renewal.
2862
        my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
2863
        $maximum_renewal_date->add(
2864
            $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
2865
        );
2866
        my $now = dt_from_string;
2867
        if ( $now >= $maximum_renewal_date ) {
2868
            return ( 0, "auto_too_late" );
2869
        }
2870
    }
2871
2856
    if ( defined $issuingrule->{norenewalbefore}
2872
    if ( defined $issuingrule->{norenewalbefore}
2857
        and $issuingrule->{norenewalbefore} ne "" )
2873
        and $issuingrule->{norenewalbefore} ne "" )
2858
    {
2874
    {
Lines 2882-2888 sub CanBookBeRenewed { Link Here
2882
2898
2883
    # Fallback for automatic renewals:
2899
    # Fallback for automatic renewals:
2884
    # If norenewalbefore is undef, don't renew before due date.
2900
    # If norenewalbefore is undef, don't renew before due date.
2885
    elsif ( $itemissue->{auto_renew} ) {
2901
    if ( $itemissue->{auto_renew} ) {
2886
        my $now = dt_from_string;
2902
        my $now = dt_from_string;
2887
        return ( 0, "auto_renew" )
2903
        return ( 0, "auto_renew" )
2888
          if $now >= $itemissue->{date_due};
2904
          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 $holds_per_record  = $input->param('holds_per_record');
142
    my $holds_per_record  = $input->param('holds_per_record');
141
    my $onshelfholds     = $input->param('onshelfholds') || 0;
143
    my $onshelfholds     = $input->param('onshelfholds') || 0;
Lines 172-177 elsif ($op eq 'add') { Link Here
172
        renewalperiod                 => $renewalperiod,
174
        renewalperiod                 => $renewalperiod,
173
        norenewalbefore               => $norenewalbefore,
175
        norenewalbefore               => $norenewalbefore,
174
        auto_renew                    => $auto_renew,
176
        auto_renew                    => $auto_renew,
177
        no_auto_renewal_after         => $no_auto_renewal_after,
175
        reservesallowed               => $reservesallowed,
178
        reservesallowed               => $reservesallowed,
176
        holds_per_record              => $holds_per_record,
179
        holds_per_record              => $holds_per_record,
177
        issuelength                   => $issuelength,
180
        issuelength                   => $issuelength,
(-)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
  `holds_per_record` SMALLINT(6) NOT NULL DEFAULT 1, -- How many holds a patron can have on a given bib
863
  `holds_per_record` SMALLINT(6) NOT NULL DEFAULT 1, -- How many holds a patron can have on a given bib
863
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
864
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (+4 lines)
Lines 185-190 $(document).ready(function() { Link Here
185
                <th>Renewal period</th>
185
                <th>Renewal period</th>
186
                <th>No renewal before</th>
186
                <th>No renewal before</th>
187
                <th>Automatic renewal</th>
187
                <th>Automatic renewal</th>
188
                <th>No automatic renewal after</th>
188
                <th>Holds allowed (count)</th>
189
                <th>Holds allowed (count)</th>
189
                <th>Holds per record (count)</th>
190
                <th>Holds per record (count)</th>
190
                <th>On shelf holds allowed</th>
191
                <th>On shelf holds allowed</th>
Lines 264-269 $(document).ready(function() { Link Here
264
                                No
265
                                No
265
                                [% END %]
266
                                [% END %]
266
                            </td>
267
                            </td>
268
                            <td>[% rule.no_auto_renewal_after %]</td>
267
							<td>[% rule.reservesallowed %]</td>
269
							<td>[% rule.reservesallowed %]</td>
268
                                                        <td>[% rule.holds_per_record %]</td>
270
                                                        <td>[% rule.holds_per_record %]</td>
269
                                                        <td>
271
                                                        <td>
Lines 339-344 $(document).ready(function() { Link Here
339
                            <option value="yes">Yes</option>
341
                            <option value="yes">Yes</option>
340
                        </select>
342
                        </select>
341
                    </td>
343
                    </td>
344
                    <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
342
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
345
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
343
                    <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
346
                    <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
344
                    <td>
347
                    <td>
Lines 383-388 $(document).ready(function() { Link Here
383
                      <th>Renewal period</th>
386
                      <th>Renewal period</th>
384
                      <th>No renewal before</th>
387
                      <th>No renewal before</th>
385
                      <th>Automatic renewal</th>
388
                      <th>Automatic renewal</th>
389
                      <th>No automatic renewal after</th>
386
                      <th>Holds allowed (count)</th>
390
                      <th>Holds allowed (count)</th>
387
                      <th>Holds per record (count)</th>
391
                      <th>Holds per record (count)</th>
388
                      <th>On shelf holds allowed</th>
392
                      <th>On shelf holds allowed</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 550-555 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
550
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
550
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
551
    );
551
    );
552
552
553
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
554
        plan tests => 8;
555
        my $item_to_auto_renew = $builder->build(
556
            {   source => 'Item',
557
                value  => {
558
                    biblionumber  => $biblionumber,
559
                    homebranch    => $branch,
560
                    holdingbranch => $branch,
561
                }
562
            }
563
        );
564
565
        my $ten_days_before = dt_from_string->add( days => -10 );
566
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
567
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
568
569
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 9');
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_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
574
575
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 10');
576
        ( $renewokay, $error ) =
577
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
578
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
579
        is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
580
581
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 11');
582
        ( $renewokay, $error ) =
583
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
584
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
585
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
586
587
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
588
        ( $renewokay, $error ) =
589
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
590
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
591
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
592
    };
593
553
    # Too many renewals
594
    # Too many renewals
554
595
555
    # set policy to forbid renewals
596
    # set policy to forbid renewals
556
- 

Return to bug 15581