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

(-)a/C4/Circulation.pm (-2 / +12 lines)
Lines 3183-3189 sub GetSoonestRenewDate { Link Here
3183
    );
3183
    );
3184
3184
3185
    my $now = dt_from_string;
3185
    my $now = dt_from_string;
3186
    return $now unless $issuing_rule;
3187
3186
3188
    if ( defined $issuing_rule->{norenewalbefore}
3187
    if ( defined $issuing_rule->{norenewalbefore}
3189
        and $issuing_rule->{norenewalbefore} ne "" )
3188
        and $issuing_rule->{norenewalbefore} ne "" )
Lines 3198-3205 sub GetSoonestRenewDate { Link Here
3198
            $soonestrenewal->truncate( to => 'day' );
3197
            $soonestrenewal->truncate( to => 'day' );
3199
        }
3198
        }
3200
        return $soonestrenewal if $now < $soonestrenewal;
3199
        return $soonestrenewal if $now < $soonestrenewal;
3200
    } elsif ( $itemissue->auto_renew && $patron->autorenew_checkouts ) {
3201
        # Checkouts with auto-renewing fall back to due date
3202
        my $soonestrenewal = return dt_from_string( $itemissue->date_due );
3203
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
3204
            and $issuing_rule->{lengthunit} eq 'days' )
3205
        {
3206
            $soonestrenewal->truncate( to => 'day' );
3207
        }
3208
        return $soonestrenewal;
3209
    } else {
3210
        # Checkouts without auto-renewing fall back to current moment
3211
        return $now;
3201
    }
3212
    }
3202
    return $now;
3203
}
3213
}
3204
3214
3205
=head2 GetLatestAutoRenewDate
3215
=head2 GetLatestAutoRenewDate
(-)a/t/db_dependent/Circulation.t (-21 / +61 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 56;
21
use Test::More tests => 57;
22
use Test::Exception;
22
use Test::Exception;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Deep qw( cmp_deeply );
24
use Test::Deep qw( cmp_deeply );
Lines 418-424 subtest "GetIssuingCharges tests" => sub { Link Here
418
418
419
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
419
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
420
subtest "CanBookBeRenewed tests" => sub {
420
subtest "CanBookBeRenewed tests" => sub {
421
    plan tests => 95;
421
    plan tests => 93;
422
422
423
    C4::Context->set_preference('ItemsDeniedRenewal','');
423
    C4::Context->set_preference('ItemsDeniedRenewal','');
424
    # Generate test biblio
424
    # Generate test biblio
Lines 856-879 subtest "CanBookBeRenewed tests" => sub { Link Here
856
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
856
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
857
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
857
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
858
858
859
    # Bug 14395
860
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
861
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' );
862
    is(
863
        GetSoonestRenewDate( $renewing_borrowernumber, $item_1->itemnumber ),
864
        $datedue->clone->add( days => -7 ),
865
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
866
    );
867
868
    # Bug 14395
869
    # Test 'date' setting for syspref NoRenewalBeforePrecision
870
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
871
    is(
872
        GetSoonestRenewDate( $renewing_borrowernumber, $item_1->itemnumber ),
873
        $datedue->clone->add( days => -7 )->truncate( to => 'day' ),
874
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
875
    );
876
877
    # Bug 14101
859
    # Bug 14101
878
    # Test premature automatic renewal
860
    # Test premature automatic renewal
879
    ( $renewokay, $error ) =
861
    ( $renewokay, $error ) =
Lines 4974-4979 subtest "SendCirculationAlert" => sub { Link Here
4974
4956
4975
};
4957
};
4976
4958
4959
subtest "GetSoonestRenewDate tests" => sub {
4960
    plan tests => 4;
4961
    Koha::CirculationRules->set_rule(
4962
        {
4963
            categorycode => undef,
4964
            branchcode   => undef,
4965
            itemtype     => undef,
4966
            rule_name    => 'norenewalbefore',
4967
            rule_value   => '7',
4968
        }
4969
    );
4970
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
4971
    my $item = $builder->build_sample_item();
4972
    my $issue = AddIssue( $patron->unblessed, $item->barcode);
4973
    my $datedue = dt_from_string( $issue->date_due() );
4974
4975
    # Bug 14395
4976
    # Test 'exact time' setting for syspref NoRenewalBeforePrecision
4977
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact_time' );
4978
    is(
4979
        GetSoonestRenewDate( $patron->id, $item->itemnumber ),
4980
        $datedue->clone->add( days => -7 ),
4981
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
4982
    );
4983
4984
    # Bug 14395
4985
    # Test 'date' setting for syspref NoRenewalBeforePrecision
4986
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
4987
    is(
4988
        GetSoonestRenewDate( $patron->id, $item->itemnumber ),
4989
        $datedue->clone->add( days => -7 )->truncate( to => 'day' ),
4990
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
4991
    );
4992
4993
4994
    Koha::CirculationRules->set_rule(
4995
        {
4996
            categorycode => undef,
4997
            branchcode   => undef,
4998
            itemtype     => undef,
4999
            rule_name    => 'norenewalbefore',
5000
            rule_value   => undef,
5001
        }
5002
    );
5003
5004
    is(
5005
        GetSoonestRenewDate( $patron->id, $item->itemnumber ),
5006
        dt_from_string,
5007
        'Checkouts without auto-renewal can be renewed immediately if no norenewalbefore'
5008
    );
5009
5010
    $issue->auto_renew(1)->store;
5011
    is(
5012
        GetSoonestRenewDate( $patron->id, $item->itemnumber ),
5013
        $datedue,
5014
        'Checkouts with auto-renewal can be renewed earliest on due date'
5015
    );
5016
};
5017
4977
$schema->storage->txn_rollback;
5018
$schema->storage->txn_rollback;
4978
C4::Context->clear_syspref_cache();
5019
C4::Context->clear_syspref_cache();
4979
$branches = Koha::Libraries->search();
5020
$branches = Koha::Libraries->search();
4980
- 

Return to bug 29476