From d08a0bc68505307da187b3b0b215cddd2b0ee742 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 Jan 2016 14:52:06 +0000 Subject: [PATCH] Bug 15582: Ability to block auto renewals if OPACFineNoRenewals is reached If a patron owes more than the OPACFineNoRenewals value, the issue won't be auto renewed anymore (driven by the new pref OPACFineNoRenewalsBlockAutoRenew). Test plan: Note: You will have to manually change data in your DB, make sure you have access to the sql cli. 1/ Set the OPACFineNoRenewals to 5 (for instance) 2/ Set OPACFineNoRenewalsBlockAutoRenew to block 3/ Check an item out to a patron and mark is as an auto renewal 4/ Make sure the patron does not have any fees or charges. 5/ Execute the automatic renewals cronjob script (misc/cronjobs/automatic_renewals.pl) Confirm that the issue has been renewed 6/ Create an invoice for this patron with a amount > OPACFineNoRenewals (6 for instance) 7/ Execute the automatic renewals cronjob script (misc/cronjobs/automatic_renewals.pl) Confirm that the issue has not been renewed. 8/ Set OPACFineNoRenewalsBlockAutoRenew to allow 9/ Execute the automatic renewals cronjob script (misc/cronjobs/automatic_renewals.pl) Confirm that the issue has been renewed Sponsored-by: University of the Arts London Signed-off-by: Jonathan Field Signed-off-by: Janet McGowan Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall --- C4/Circulation.pm | 8 ++++ .../prog/en/modules/circ/renew.tt | 2 +- t/db_dependent/Circulation.t | 42 ++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 7147e2177f..a439021ba3 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2774,6 +2774,14 @@ sub CanBookBeRenewed { return ( 0, "auto_too_late" ); } } + + 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 $issuing_rule->norenewalbefore diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt index b63d7a44d6..dbcc09688d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt @@ -90,7 +90,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.

diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 12631226b0..9a5b821309 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 94; +use Test::More tests => 95; use DateTime; @@ -637,6 +637,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 => 5; my $item_to_auto_renew = $builder->build( -- 2.39.5