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

(-)a/C4/Circulation.pm (+5 lines)
Lines 2699-2704 sub CanBookBeRenewed { Link Here
2699
    }
2699
    }
2700
2700
2701
    if ( $issue->auto_renew ) {
2701
    if ( $issue->auto_renew ) {
2702
2703
        if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2704
            return ( 0, 'auto_account_expired' );
2705
        }
2706
2702
        if ( defined $issuing_rule->no_auto_renewal_after
2707
        if ( defined $issuing_rule->no_auto_renewal_after
2703
                and $issuing_rule->no_auto_renewal_after ne "" ) {
2708
                and $issuing_rule->no_auto_renewal_after ne "" ) {
2704
            # Get issue_date and add no_auto_renewal_after
2709
            # Get issue_date and add no_auto_renewal_after
(-)a/misc/cronjobs/automatic_renewals.pl (+1 lines)
Lines 85-90 while ( my $auto_renew = $auto_renews->next ) { Link Here
85
        or $error eq 'on_reserve'
85
        or $error eq 'on_reserve'
86
        or $error eq 'restriction'
86
        or $error eq 'restriction'
87
        or $error eq 'overdue'
87
        or $error eq 'overdue'
88
        or $error eq 'auto_account_expired'
88
        or $error eq 'auto_too_late'
89
        or $error eq 'auto_too_late'
89
        or $error eq 'auto_too_much_oweing'
90
        or $error eq 'auto_too_much_oweing'
90
        or $error eq 'auto_too_soon' ) {
91
        or $error eq 'auto_too_soon' ) {
(-)a/t/db_dependent/Circulation.t (-3 / +73 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 112;
20
use Test::More tests => 113;
21
21
22
use DateTime;
22
use DateTime;
23
23
Lines 63-69 my $itemtype = $builder->build( Link Here
63
        value  => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef }
63
        value  => { notforloan => undef, rentalcharge => 0, defaultreplacecost => undef, processfee => undef }
64
    }
64
    }
65
)->{itemtype};
65
)->{itemtype};
66
my $patron_category = $builder->build({ source => 'Category', value => { category_type => 'P', enrolmentfee => 0 } });
66
my $patron_category = $builder->build(
67
    {
68
        source => 'Category',
69
        value  => {
70
            category_type                 => 'P',
71
            enrolmentfee                  => 0,
72
            BlockExpiredPatronOpacActions => -1, # Pick the pref value
73
        }
74
    }
75
);
67
76
68
my $CircControl = C4::Context->preference('CircControl');
77
my $CircControl = C4::Context->preference('CircControl');
69
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
78
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
Lines 290-302 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
290
        branchcode => $branch,
299
        branchcode => $branch,
291
    );
300
    );
292
301
302
    my %expired_borrower_data = (
303
        firstname =>  'Ça',
304
        surname => 'Glisse',
305
        categorycode => $patron_category->{categorycode},
306
        branchcode => $branch,
307
        dateexpiry => dt_from_string->subtract( months => 1 ),
308
    );
309
293
    my $renewing_borrowernumber = AddMember(%renewing_borrower_data);
310
    my $renewing_borrowernumber = AddMember(%renewing_borrower_data);
294
    my $reserving_borrowernumber = AddMember(%reserving_borrower_data);
311
    my $reserving_borrowernumber = AddMember(%reserving_borrower_data);
295
    my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data);
312
    my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data);
296
    my $restricted_borrowernumber = AddMember(%restricted_borrower_data);
313
    my $restricted_borrowernumber = AddMember(%restricted_borrower_data);
314
    my $expired_borrowernumber = AddMember(%expired_borrower_data);
297
315
298
    my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed;
316
    my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed;
299
    my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed;
317
    my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed;
318
    my $expired_borrower = Koha::Patrons->find( $expired_borrowernumber )->unblessed;
300
319
301
    my $bibitems       = '';
320
    my $bibitems       = '';
302
    my $priority       = '1';
321
    my $priority       = '1';
Lines 695-700 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
695
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
714
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
696
    };
715
    };
697
716
717
    subtest "auto_account_expired | BlockExpiredPatronOpacActions" => sub {
718
        plan tests => 6;
719
        my $item_to_auto_renew = $builder->build({
720
            source => 'Item',
721
            value => {
722
                biblionumber => $biblionumber,
723
                homebranch       => $branch,
724
                holdingbranch    => $branch,
725
            }
726
        });
727
728
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
729
730
        my $ten_days_before = dt_from_string->add( days => -10 );
731
        my $ten_days_ahead = dt_from_string->add( days => 10 );
732
733
        # Patron is expired and BlockExpiredPatronOpacActions=0
734
        # => auto renew is allowed
735
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
736
        my $patron = $expired_borrower;
737
        my $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
738
        ( $renewokay, $error ) =
739
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
740
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
741
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
742
        Koha::Checkouts->find( $checkout->issue_id )->delete;
743
744
745
        # Patron is expired and BlockExpiredPatronOpacActions=1
746
        # => auto renew is not allowed
747
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
748
        $patron = $expired_borrower;
749
        $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
750
        ( $renewokay, $error ) =
751
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
752
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
753
        is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' );
754
        Koha::Checkouts->find( $checkout->issue_id )->delete;
755
756
757
        # Patron is not expired and BlockExpiredPatronOpacActions=1
758
        # => auto renew is allowed
759
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
760
        $patron = $renewing_borrower;
761
        $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
762
        ( $renewokay, $error ) =
763
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
764
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
765
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
766
        Koha::Checkouts->find( $checkout->issue_id )->delete;
767
    };
768
698
    subtest "GetLatestAutoRenewDate" => sub {
769
    subtest "GetLatestAutoRenewDate" => sub {
699
        plan tests => 5;
770
        plan tests => 5;
700
        my $item_to_auto_renew = $builder->build(
771
        my $item_to_auto_renew = $builder->build(
701
- 

Return to bug 19444