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 173-178 elsif ($op eq 'add') { Link Here
173
        renewalperiod                 => $renewalperiod,
175
        renewalperiod                 => $renewalperiod,
174
        norenewalbefore               => $norenewalbefore,
176
        norenewalbefore               => $norenewalbefore,
175
        auto_renew                    => $auto_renew,
177
        auto_renew                    => $auto_renew,
178
        no_auto_renewal_after         => $no_auto_renewal_after,
176
        reservesallowed               => $reservesallowed,
179
        reservesallowed               => $reservesallowed,
177
        holds_per_record              => $holds_per_record,
180
        holds_per_record              => $holds_per_record,
178
        issuelength                   => $issuelength,
181
        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 869-874 CREATE TABLE `issuingrules` ( -- circulation and fine rules Link Here
869
  `renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit
869
  `renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit
870
  `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date.
870
  `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date.
871
  `auto_renew` BOOLEAN default FALSE, -- automatic renewal
871
  `auto_renew` BOOLEAN default FALSE, -- automatic renewal
872
  `no_auto_renewal_after` int(4) default NULL, -- no auto renewal allowed after X days or hours after the issue date
872
  `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
873
  `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
873
  `holds_per_record` SMALLINT(6) NOT NULL DEFAULT 1, -- How many holds a patron can have on a given bib
874
  `holds_per_record` SMALLINT(6) NOT NULL DEFAULT 1, -- How many holds a patron can have on a given bib
874
  `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
875
  `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 265-270 $(document).ready(function() { Link Here
265
                                No
266
                                No
266
                                [% END %]
267
                                [% END %]
267
                            </td>
268
                            </td>
269
                            <td>[% rule.no_auto_renewal_after %]</td>
268
							<td>[% rule.reservesallowed %]</td>
270
							<td>[% rule.reservesallowed %]</td>
269
                                                        <td>[% rule.holds_per_record %]</td>
271
                                                        <td>[% rule.holds_per_record %]</td>
270
                                                        <td>
272
                                                        <td>
Lines 351-356 $(document).ready(function() { Link Here
351
                            <option value="yes">Yes</option>
353
                            <option value="yes">Yes</option>
352
                        </select>
354
                        </select>
353
                    </td>
355
                    </td>
356
                    <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
354
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
357
                    <td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
355
                    <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
358
                    <td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
356
                    <td>
359
                    <td>
Lines 403-408 $(document).ready(function() { Link Here
403
                      <th>Renewal period</th>
406
                      <th>Renewal period</th>
404
                      <th>No renewal before</th>
407
                      <th>No renewal before</th>
405
                      <th>Automatic renewal</th>
408
                      <th>Automatic renewal</th>
409
                      <th>No automatic renewal after</th>
406
                      <th>Holds allowed (count)</th>
410
                      <th>Holds allowed (count)</th>
407
                      <th>Holds per record (count)</th>
411
                      <th>Holds per record (count)</th>
408
                      <th>On shelf holds allowed</th>
412
                      <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 (-2 / +41 lines)
Lines 37-43 use C4::Overdues qw(UpdateFine CalcFine); Link Here
37
use Koha::DateUtils;
37
use Koha::DateUtils;
38
use Koha::Database;
38
use Koha::Database;
39
39
40
41
my $schema = Koha::Database->schema;
40
my $schema = Koha::Database->schema;
42
$schema->storage->txn_begin;
41
$schema->storage->txn_begin;
43
my $builder = t::lib::TestBuilder->new;
42
my $builder = t::lib::TestBuilder->new;
Lines 553-558 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
553
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
552
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
554
    );
553
    );
555
554
555
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
556
        plan tests => 8;
557
        my $item_to_auto_renew = $builder->build(
558
            {   source => 'Item',
559
                value  => {
560
                    biblionumber  => $biblionumber,
561
                    homebranch    => $branch,
562
                    holdingbranch => $branch,
563
                }
564
            }
565
        );
566
567
        my $ten_days_before = dt_from_string->add( days => -10 );
568
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
569
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
570
571
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 9');
572
        ( $renewokay, $error ) =
573
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
574
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
575
        is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
576
577
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 10');
578
        ( $renewokay, $error ) =
579
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
580
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
581
        is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
582
583
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 11');
584
        ( $renewokay, $error ) =
585
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
586
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
587
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
588
589
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
590
        ( $renewokay, $error ) =
591
          CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
592
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
593
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
594
    };
595
556
    # Too many renewals
596
    # Too many renewals
557
597
558
    # set policy to forbid renewals
598
    # set policy to forbid renewals
559
- 

Return to bug 15581