return ( 0, 'overdue');
}
+ if ( $itemissue->{auto_renew}
+ and defined $issuingrule->{no_auto_renewal_after}
+ and $issuingrule->{no_auto_renewal_after} ne "" ) {
+
+ # Get issue_date and add no_auto_renewal_after
+ # If this is greater than today, it's too late for renewal.
+ my $maximum_renewal_date = dt_from_string($itemissue->{issuedate});
+ $maximum_renewal_date->add(
+ $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after}
+ );
+ my $now = dt_from_string;
+ if ( $now >= $maximum_renewal_date ) {
+ return ( 0, "auto_too_late" );
+ }
+ }
+
if ( defined $issuingrule->{norenewalbefore}
and $issuingrule->{norenewalbefore} ne "" )
{
# Fallback for automatic renewals:
# If norenewalbefore is undef, don't renew before due date.
- elsif ( $itemissue->{auto_renew} ) {
+ if ( $itemissue->{auto_renew} ) {
my $now = dt_from_string;
return ( 0, "auto_renew" )
if $now >= $itemissue->{date_due};
my $norenewalbefore = $input->param('norenewalbefore');
$norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
+ my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
+ $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
my $reservesallowed = $input->param('reservesallowed');
my $holds_per_record = $input->param('holds_per_record');
my $onshelfholds = $input->param('onshelfholds') || 0;
renewalperiod => $renewalperiod,
norenewalbefore => $norenewalbefore,
auto_renew => $auto_renew,
+ no_auto_renewal_after => $no_auto_renewal_after,
reservesallowed => $reservesallowed,
holds_per_record => $holds_per_record,
issuelength => $issuelength,
--- /dev/null
+ALTER TABLE issuingrules ADD COLUMN no_auto_renewal_after INT(4) DEFAULT NULL AFTER auto_renew;
`renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit
`norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date.
`auto_renew` BOOLEAN default FALSE, -- automatic renewal
+ `no_auto_renewal_after` int(4) default NULL, -- no auto renewal allowed after X days or hours after the issue date
`reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed
`holds_per_record` SMALLINT(6) NOT NULL DEFAULT 1, -- How many holds a patron can have on a given bib
`branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode)
<th>Renewal period</th>
<th>No renewal before</th>
<th>Automatic renewal</th>
+ <th>No automatic renewal after</th>
<th>Holds allowed (count)</th>
<th>Holds per record (count)</th>
<th>On shelf holds allowed</th>
No
[% END %]
</td>
+ <td>[% rule.no_auto_renewal_after %]</td>
<td>[% rule.reservesallowed %]</td>
<td>[% rule.holds_per_record %]</td>
<td>
<option value="yes">Yes</option>
</select>
</td>
+ <td><input type="text" name="no_auto_renewal_after" id="no_auto_renewal_after" size="3" /></td>
<td><input type="text" name="reservesallowed" id="reservesallowed" size="2" /></td>
<td><input type="text" name="holds_per_record" id="holds_per_record" size="2" /></td>
<td>
<th>Renewal period</th>
<th>No renewal before</th>
<th>Automatic renewal</th>
+ <th>No automatic renewal after</th>
<th>Holds allowed (count)</th>
<th>Holds per record (count)</th>
<th>On shelf holds allowed</th>
</form>
[% END %]
+ [% ELSIF error == "auto_too_late" %]
+
+ <p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal and cannot be renewed since [% latestrenewdate | $KohaDates %]. </p>
+
+ [% IF Koha.Preference('AllowRenewalLimitOverride') %]
+ <form method="post" action="/cgi-bin/koha/circ/renew.pl">
+ <input type="hidden" name="barcode" value="[% item.barcode %]"/>
+ <input type="hidden" name="override_limit" value="1" />
+ <input type="submit" class="approve" value="Override and renew" />
+ </form>
+ [% END %]
+
[% ELSIF error == "auto_renew" %]
<p>[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal. </p>
use Modern::Perl;
-use Test::More tests => 88;
+use Test::More tests => 90;
BEGIN {
require_ok('C4::Circulation');
use Koha::DateUtils;
use Koha::Database;
-
my $schema = Koha::Database->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
);
+ subtest "too_late_renewal / no_auto_renewal_after" => sub {
+ plan tests => 8;
+ my $item_to_auto_renew = $builder->build(
+ { source => 'Item',
+ value => {
+ biblionumber => $biblionumber,
+ homebranch => $branch,
+ holdingbranch => $branch,
+ }
+ }
+ );
+
+ my $ten_days_before = dt_from_string->add( days => -10 );
+ my $ten_days_ahead = dt_from_string->add( days => 10 );
+ AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
+
+ $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 9');
+ ( $renewokay, $error ) =
+ CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
+ is( $renewokay, 0, 'Do not renew, renewal is automatic' );
+ is( $error, 'auto_too_late', 'Cannot renew, too late(returned code is auto_too_late)' );
+
+ $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 10');
+ ( $renewokay, $error ) =
+ CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
+ is( $renewokay, 0, 'Do not renew, renewal is automatic' );
+ is( $error, 'auto_too_late', 'Cannot auto renew, too late - no_auto_renewal_after is inclusive(returned code is auto_too_late)' );
+
+ $dbh->do('UPDATE issuingrules SET norenewalbefore = 7, no_auto_renewal_after = 11');
+ ( $renewokay, $error ) =
+ CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
+ is( $renewokay, 0, 'Do not renew, renewal is automatic' );
+ is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
+
+ $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
+ ( $renewokay, $error ) =
+ CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} );
+ is( $renewokay, 0, 'Do not renew, renewal is automatic' );
+ is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
+ };
+
# Too many renewals
# set policy to forbid renewals