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 / +74 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 => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
66
my $patron_category = $builder->build(
67
    {
68
        source => 'Category',
69
        value  => {
70
            categorycode                  => 'NOT_X',
71
            category_type                 => 'P',
72
            enrolmentfee                  => 0,
73
            BlockExpiredPatronOpacActions => -1, # Pick the pref value
74
        }
75
    }
76
);
67
77
68
my $CircControl = C4::Context->preference('CircControl');
78
my $CircControl = C4::Context->preference('CircControl');
69
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
79
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
Lines 290-302 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
290
        branchcode => $branch,
300
        branchcode => $branch,
291
    );
301
    );
292
302
303
    my %expired_borrower_data = (
304
        firstname =>  'Ça',
305
        surname => 'Glisse',
306
        categorycode => $patron_category->{categorycode},
307
        branchcode => $branch,
308
        dateexpiry => dt_from_string->subtract( months => 1 ),
309
    );
310
293
    my $renewing_borrowernumber = AddMember(%renewing_borrower_data);
311
    my $renewing_borrowernumber = AddMember(%renewing_borrower_data);
294
    my $reserving_borrowernumber = AddMember(%reserving_borrower_data);
312
    my $reserving_borrowernumber = AddMember(%reserving_borrower_data);
295
    my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data);
313
    my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data);
296
    my $restricted_borrowernumber = AddMember(%restricted_borrower_data);
314
    my $restricted_borrowernumber = AddMember(%restricted_borrower_data);
315
    my $expired_borrowernumber = AddMember(%expired_borrower_data);
297
316
298
    my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed;
317
    my $renewing_borrower = Koha::Patrons->find( $renewing_borrowernumber )->unblessed;
299
    my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed;
318
    my $restricted_borrower = Koha::Patrons->find( $restricted_borrowernumber )->unblessed;
319
    my $expired_borrower = Koha::Patrons->find( $expired_borrowernumber )->unblessed;
300
320
301
    my $bibitems       = '';
321
    my $bibitems       = '';
302
    my $priority       = '1';
322
    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);
715
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
696
    };
716
    };
697
717
718
    subtest "auto_account_expired | BlockExpiredPatronOpacActions" => sub {
719
        plan tests => 6;
720
        my $item_to_auto_renew = $builder->build({
721
            source => 'Item',
722
            value => {
723
                biblionumber => $biblionumber,
724
                homebranch       => $branch,
725
                holdingbranch    => $branch,
726
            }
727
        });
728
729
        $dbh->do('UPDATE issuingrules SET norenewalbefore = 10, no_auto_renewal_after = 11');
730
731
        my $ten_days_before = dt_from_string->add( days => -10 );
732
        my $ten_days_ahead = dt_from_string->add( days => 10 );
733
734
        # Patron is expired and BlockExpiredPatronOpacActions=0
735
        # => auto renew is allowed
736
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 0);
737
        my $patron = $expired_borrower;
738
        my $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
739
        ( $renewokay, $error ) =
740
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
741
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
742
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
743
        Koha::Checkouts->find( $checkout->issue_id )->delete;
744
745
746
        # Patron is expired and BlockExpiredPatronOpacActions=1
747
        # => auto renew is not allowed
748
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
749
        $patron = $expired_borrower;
750
        $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
751
        ( $renewokay, $error ) =
752
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
753
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
754
        is( $error, 'auto_account_expired', 'Can not auto renew, lockExpiredPatronOpacActions=1 and patron is expired' );
755
        Koha::Checkouts->find( $checkout->issue_id )->delete;
756
757
758
        # Patron is not expired and BlockExpiredPatronOpacActions=1
759
        # => auto renew is allowed
760
        t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
761
        $patron = $renewing_borrower;
762
        $checkout = AddIssue( $patron, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
763
        ( $renewokay, $error ) =
764
          CanBookBeRenewed( $patron->{borrowernumber}, $item_to_auto_renew->{itemnumber} );
765
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
766
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
767
        Koha::Checkouts->find( $checkout->issue_id )->delete;
768
    };
769
698
    subtest "GetLatestAutoRenewDate" => sub {
770
    subtest "GetLatestAutoRenewDate" => sub {
699
        plan tests => 5;
771
        plan tests => 5;
700
        my $item_to_auto_renew = $builder->build(
772
        my $item_to_auto_renew = $builder->build(
701
- 

Return to bug 19444