@@ -, +, @@ OPACFineNoRenewals is reached --- C4/Circulation.pm | 8 +++++ .../intranet-tmpl/prog/en/modules/circ/renew.tt | 2 +- t/db_dependent/Circulation.t | 42 +++++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2905,6 +2905,14 @@ sub CanBookBeRenewed { } } + if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { + my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); + my ( $amountoutstanding ) = C4::Members::GetMemberAccountRecords($borrower->{borrowernumber}); + if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { + return ( 0, "auto_too_much_oweing" ); + } + } + if ( defined $issuingrule->{norenewalbefore} and $issuingrule->{norenewalbefore} ne "" ) { --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt @@ -89,7 +89,7 @@ [% END %] - [% ELSIF error == "auto_renew" %] + [% ELSIF error == "auto_renew" or error == "auto_too_much_oweing" %]

[% item.biblio.title %] [% item.biblioitem.subtitle %] ( [% item.barcode %] ) has been scheduled for automatic renewal.

--- a/t/db_dependent/Circulation.t +++ a/t/db_dependent/Circulation.t @@ -30,7 +30,7 @@ use Koha::Database; use t::lib::TestBuilder; -use Test::More tests => 84; +use Test::More tests => 85; BEGIN { use_ok('C4::Circulation'); @@ -573,6 +573,46 @@ C4::Context->dbh->do("DELETE FROM accountlines"); is( $error, 'auto_renew', 'Cannot renew, renew is automatic' ); }; + subtest "auto_too_much_oweing | OPACFineNoRenewalsBlockAutoRenew" => sub { + plan tests => 6; + 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 = 10, no_auto_renewal_after = 11'); + C4::Context->set_preference('OPACFineNoRenewalsBlockAutoRenew','1'); + C4::Context->set_preference('OPACFineNoRenewals','10'); + my $fines_amount = 5; + C4::Accounts::manualinvoice( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber}, "Some fines", 'F', $fines_amount ); + ( $renewokay, $error ) = + CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); + is( $renewokay, 0, 'Do not renew, renewal is automatic' ); + is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' ); + + C4::Accounts::manualinvoice( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber}, "Some fines", 'F', $fines_amount ); + ( $renewokay, $error ) = + CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); + is( $renewokay, 0, 'Do not renew, renewal is automatic' ); + is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' ); + + C4::Accounts::manualinvoice( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber}, "Some fines", 'F', $fines_amount ); + ( $renewokay, $error ) = + CanBookBeRenewed( $renewing_borrowernumber, $item_to_auto_renew->{itemnumber} ); + is( $renewokay, 0, 'Do not renew, renewal is automatic' ); + is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, patron has 15' ); + + $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber); + }; + subtest "GetLatestAutoRenewDate" => sub { plan tests => 3; my $item_to_auto_renew = $builder->build( --