@@ -, +, @@ - a small error in the checkouts related JS - GetRenewCount now returns 6 values when a call to it succeeds, a - Some changes in issue.t had broken the tests for unseen renewals (the - Also now using Koha::CirculationRules::set_rules to set circ rules - Fixed expected number of return values from GetRenewCount - Moved unseen tests in issue.t to the bottom of the file to remove the - There was a real mess in C4/Circulation.pm due to a bad rebase back in - Somehow I'd never noticed this before but the columns in smart-rules.tt - This commit also fixes items 1 & 2 descibed by Katrin in comment #74 -> - Fixed missing check for too_unseen in opac-user.tt, this test did used - Added test for too_unseen to all AUTO_RENEWAL notice templates apart --- C4/Circulation.pm | 119 +----------------- .../mysql/en/mandatory/sample_notices.yml | 2 + .../fr-CA/obligatoire/sample_notices.sql | 2 + .../fr-FR/1-Obligatoire/sample_notices.sql | 2 + .../data/mysql/it-IT/necessari/notices.sql | 2 + .../nb-NO/1-Obligatorisk/sample_notices.sql | 2 + .../mysql/pl-PL/mandatory/sample_notices.sql | 2 + .../mysql/ru-RU/mandatory/sample_notices.sql | 2 + .../mysql/uk-UA/mandatory/sample_notices.sql | 2 + .../prog/en/modules/admin/smart-rules.tt | 4 +- koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 6 +- .../bootstrap/en/modules/opac-user.tt | 2 + t/db_dependent/Circulation.t | 28 ++++- t/db_dependent/Circulation/issue.t | 64 ++++++---- 14 files changed, 95 insertions(+), 144 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2781,6 +2781,11 @@ sub CanBookBeRenewed { return ( 0, "too_many" ) if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; + return ( 0, "too_unseen" ) + if C4::Context->preference('UnseenRenewals') && + $issuing_rule->{unseen_renewals_allowed} && + $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; + my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); $patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? @@ -2952,118 +2957,6 @@ sub CanBookBeRenewed { return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed - return ( 1, undef ) if $override_limit; - - my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); - my $issuing_rule = Koha::CirculationRules->get_effective_rules( - { - categorycode => $patron->categorycode, - itemtype => $item->effective_itemtype, - branchcode => $branchcode, - rules => [ - 'renewalsallowed', - 'no_auto_renewal_after', - 'no_auto_renewal_after_hard_limit', - 'lengthunit', - 'norenewalbefore', - 'unseen_renewals_allowed' - ] - } - ); - - return ( 0, "too_many" ) - if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; - - return ( 0, "too_unseen" ) - if C4::Context->preference('UnseenRenewals') && - $issuing_rule->{unseen_renewals_allowed} && - $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; - - my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); - my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); - $patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? - my $restricted = $patron->is_debarred; - my $hasoverdues = $patron->has_overdues; - - if ( $restricted and $restrictionblockrenewing ) { - return ( 0, 'restriction'); - } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { - return ( 0, 'overdue'); - } - - if ( $issue->auto_renew ) { - - if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { - return ( 0, 'auto_account_expired' ); - } - - if ( defined $issuing_rule->{no_auto_renewal_after} - and $issuing_rule->{no_auto_renewal_after} ne "" ) { - # Get issue_date and add no_auto_renewal_after - # If this is greater than today, it's too late for renewal. - my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); - $maximum_renewal_date->add( - $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after} - ); - my $now = dt_from_string; - if ( $now >= $maximum_renewal_date ) { - return ( 0, "auto_too_late" ); - } - } - if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit} - and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) { - # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal - if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) { - return ( 0, "auto_too_late" ); - } - } - - if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { - my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); - my $amountoutstanding = - C4::Context->preference("OPACFineNoRenewalsIncludeCredit") - ? $patron->account->balance - : $patron->account->outstanding_debits->total_outstanding; - if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { - return ( 0, "auto_too_much_oweing" ); - } - } - } - - if ( defined $issuing_rule->{norenewalbefore} - and $issuing_rule->{norenewalbefore} ne "" ) - { - - # Calculate soonest renewal by subtracting 'No renewal before' from due date - my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( - $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); - - # Depending on syspref reset the exact time, only check the date - if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' - and $issuing_rule->{lengthunit} eq 'days' ) - { - $soonestrenewal->truncate( to => 'day' ); - } - - if ( $soonestrenewal > dt_from_string() ) - { - return ( 0, "auto_too_soon" ) if $issue->auto_renew; - return ( 0, "too_soon" ); - } - elsif ( $issue->auto_renew ) { - return ( 0, "auto_renew" ); - } - } - - # Fallback for automatic renewals: - # If norenewalbefore is undef, don't renew before due date. - if ( $issue->auto_renew ) { - my $now = dt_from_string; - return ( 0, "auto_renew" ) - if $now >= dt_from_string( $issue->date_due, 'sql' ); - return ( 0, "auto_too_soon" ); - } - return ( 1, undef ); } @@ -3287,7 +3180,7 @@ sub GetRenewCount { my $patron = Koha::Patrons->find( $bornum ); my $item = Koha::Items->find($itemno); - return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed + return (0, 0, 0, 0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed # Look in the issues table for this item, lent to this borrower, # and not yet returned. --- a/installer/data/mysql/en/mandatory/sample_notices.yml +++ a/installer/data/mysql/en/mandatory/sample_notices.yml @@ -1204,6 +1204,8 @@ tables: - "It's too late to renew this item." - "[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]" - "Your total unpaid fines are too high." + - "[% ELSIF checkout.auto_renew_error == 'too_unseen' %]" + - "This item must be renewed at the library." - "[% END %]" - "[% ELSE %]" - "The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %]" --- a/installer/data/mysql/fr-CA/obligatoire/sample_notices.sql +++ a/installer/data/mysql/fr-CA/obligatoire/sample_notices.sql @@ -285,6 +285,8 @@ You have overdue items. It\'s too late to renew this item. [% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %] Your total unpaid fines are too high. +[% ELSIF checkout.auto_renew_error == 'too_unseen' %] +This item must be renewed at the library. [% END %] [% ELSE %] The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %] --- a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql +++ a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql @@ -396,6 +396,8 @@ You have overdue items. It\'s too late to renew this item. [% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %] Your total unpaid fines are too high. +[% ELSIF checkout.auto_renew_error == 'too_unseen' %] +This item must be renewed at the library. [% END %] [% ELSE %] The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %] --- a/installer/data/mysql/it-IT/necessari/notices.sql +++ a/installer/data/mysql/it-IT/necessari/notices.sql @@ -399,6 +399,8 @@ You have overdue items. It\'s too late to renew this item. [% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %] Your total unpaid fines are too high. +[% ELSIF checkout.auto_renew_error == 'too_unseen' %] +This item must be renewed at the library. [% END %] [% ELSE %] The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %] --- a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql +++ a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql @@ -414,6 +414,8 @@ You have overdue items. It\'s too late to renew this item. [% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %] Your total unpaid fines are too high. +[% ELSIF checkout.auto_renew_error == 'too_unseen' %] +This item must be renewed at the library. [% END %] [% ELSE %] The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %] --- a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql +++ a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql @@ -393,6 +393,8 @@ You have overdue items. It\'s too late to renew this item. [% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %] Your total unpaid fines are too high. +[% ELSIF checkout.auto_renew_error == 'too_unseen' %] +This item must be renewed at the library. [% END %] [% ELSE %] The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %] --- a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql +++ a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql @@ -395,6 +395,8 @@ You have overdue items. It\'s too late to renew this item. [% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %] Your total unpaid fines are too high. +[% ELSIF checkout.auto_renew_error == 'too_unseen' %] +This item must be renewed at the library. [% END %] [% ELSE %] The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %] --- a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql +++ a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql @@ -486,6 +486,8 @@ You have overdue items. It\'s too late to renew this item. [% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %] Your total unpaid fines are too high. +[% ELSIF checkout.auto_renew_error == 'too_unseen' %] +This item must be renewed at the library. [% END %] [% ELSE %] The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -417,7 +417,9 @@