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

(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 2743-2749 sub CanBookBeRenewed { Link Here
2743
            return ( 0, 'overdue');
2743
            return ( 0, 'overdue');
2744
        }
2744
        }
2745
2745
2746
        if ( $issue->auto_renew ) {
2746
        if ( $issue->auto_renew && $patron->autorenewal ) {
2747
2747
2748
            if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2748
            if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2749
                return ( 0, 'auto_account_expired' );
2749
                return ( 0, 'auto_account_expired' );
Lines 2799-2808 sub CanBookBeRenewed { Link Here
2799
2799
2800
            if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) )
2800
            if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) )
2801
            {
2801
            {
2802
                return ( 0, "auto_too_soon" ) if $issue->auto_renew;
2802
                return ( 0, "auto_too_soon" ) if $issue->auto_renew && $patron->autorenewal;
2803
                return ( 0, "too_soon" );
2803
                return ( 0, "too_soon" );
2804
            }
2804
            }
2805
            elsif ( $issue->auto_renew ) {
2805
            elsif ( $issue->auto_renew && $patron->autorenewal ) {
2806
                $auto_renew = 1;
2806
                $auto_renew = 1;
2807
            }
2807
            }
2808
        }
2808
        }
(-)a/t/db_dependent/Circulation.t (-2 / +25 lines)
Lines 355-361 subtest "CanBookBeRenewed tests" => sub { Link Here
355
    my $restricted_borrowernumber = Koha::Patron->new(\%restricted_borrower_data)->store->borrowernumber;
355
    my $restricted_borrowernumber = Koha::Patron->new(\%restricted_borrower_data)->store->borrowernumber;
356
    my $expired_borrowernumber = Koha::Patron->new(\%expired_borrower_data)->store->borrowernumber;
356
    my $expired_borrowernumber = Koha::Patron->new(\%expired_borrower_data)->store->borrowernumber;
357
357
358
    my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed;
358
    my $renewing_borrower_obj = Koha::Patrons->find( $renewing_borrowernumber );
359
    my $renewing_borrower = $renewing_borrower_obj->unblessed;
359
    my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed;
360
    my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed;
360
    my $expired_borrower = Koha::Patrons->find( $expired_borrowernumber )->unblessed;
361
    my $expired_borrower = Koha::Patrons->find( $expired_borrowernumber )->unblessed;
361
362
Lines 656-661 subtest "CanBookBeRenewed tests" => sub { Link Here
656
657
657
658
658
659
660
    $renewing_borrower_obj->autorenewal(0)->store;
661
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
662
    is( $renewokay, 1, 'No renewal before is undef, but patron opted out of auto_renewal' );
663
    $renewing_borrower_obj->autorenewal(1)->store;
664
665
659
    # Bug 7413
666
    # Bug 7413
660
    # Test premature manual renewal
667
    # Test premature manual renewal
661
    Koha::CirculationRules->set_rule(
668
    Koha::CirculationRules->set_rule(
Lines 699-704 subtest "CanBookBeRenewed tests" => sub { Link Here
699
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
706
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
700
    );
707
    );
701
708
709
    $renewing_borrower_obj->autorenewal(0)->store;
710
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
711
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
712
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
713
    $renewing_borrower_obj->autorenewal(1)->store;
714
702
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
715
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
703
    # and test automatic renewal again
716
    # and test automatic renewal again
704
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
717
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
Lines 709-714 subtest "CanBookBeRenewed tests" => sub { Link Here
709
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
722
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
710
    );
723
    );
711
724
725
    $renewing_borrower_obj->autorenewal(0)->store;
726
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
727
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
728
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
729
    $renewing_borrower_obj->autorenewal(1)->store;
730
712
    # Change policy so that loans can be renewed 99 days prior to the due date
731
    # Change policy so that loans can be renewed 99 days prior to the due date
713
    # and test automatic renewal again
732
    # and test automatic renewal again
714
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
733
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
Lines 719-724 subtest "CanBookBeRenewed tests" => sub { Link Here
719
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
738
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
720
    );
739
    );
721
740
741
    $renewing_borrower_obj->autorenewal(0)->store;
742
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
743
    is( $renewokay, 1, 'No renewal before is 99, patron opted out of auto_renewal so can renew' );
744
    $renewing_borrower_obj->autorenewal(1)->store;
745
722
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
746
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
723
        plan tests => 14;
747
        plan tests => 14;
724
        my $item_to_auto_renew = $builder->build(
748
        my $item_to_auto_renew = $builder->build(
725
- 

Return to bug 24476