Bugzilla – Attachment 96689 Details for
Bug 19014
Patrons should not get an 'on_reserve' notification if the due date is far into the future
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19014: Return auto_too_soon before on_reserve
Bug-19014-Return-autotoosoon-before-onreserve.patch (text/plain), 10.80 KB, created by
Nick Clemens (kidclamp)
on 2019-12-30 19:36:08 UTC
(
hide
)
Description:
Bug 19014: Return auto_too_soon before on_reserve
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2019-12-30 19:36:08 UTC
Size:
10.80 KB
patch
obsolete
>From 85f37eac58b7c03f1bc5b361e34731e3e6eadea4 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 30 Dec 2019 19:27:38 +0000 >Subject: [PATCH] Bug 19014: Return auto_too_soon before on_reserve > >When calling CanBookBeRenewed we do check for 'too_soon', however, a reserve >makes the return 'on_reserve' before other statuses. It seems the patron specific reasons >should be returned first. This patch places the 'on_reserve' check after too_soon and others > >To test: > 1 - Checkout an item to a patron with a due date 2 days in the future and 'No renewal before' unset > 2 - Place a hold on that item > 3 - Define an AUTO_RENEWALS circulation notice with below at a minimum > [% checkout.auto_renew_error %] > 4 - perl misc/cronjobs/automatic_renewals.pl --send-notices > 5 - Patron is not notified > 6 - Set 'No renewal before' to 1 > 7 - run cronjob > 8 - Patron is notified with error 'on_reserve' > 9 - Set 'No renewal before' to 3 >10 - UPDATE issues SET auto_renew_error = NULL; >11 - run cronjob >12 - Patron is notified with error 'on_reserve' >13 - APPLY PATCH >14 - Unset 'No renewal before' >15 - UPDATE issues SET auto_renew_error = NULL; >16 - run cronjob >17 - Patron is not notified >18 - UPDATE issues SET auto_renew_error = NULL; >19 - Set 'No renewal before' to 1 >20 - run cronjob >21 - Patron is notified with error 'on_reserve' >22 - Set 'No renewal before' to 3 >23 - UPDATE issues SET auto_renew_error = NULL; >24 - run cronjob >25 - Patron is not notified >--- > C4/Circulation.pm | 197 +++++++++++++++++++++++++++--------------------------- > 1 file changed, 99 insertions(+), 98 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 3568a32639..2c5eea1ae4 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2677,6 +2677,105 @@ sub CanBookBeRenewed { > > my $patron = $issue->patron or return; > >+ # override_limit will override anything else except on_reserve >+ unless ( $override_limit ){ >+ my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); >+ my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( >+ { categorycode => $patron->categorycode, >+ itemtype => $item->effective_itemtype, >+ branchcode => $branchcode >+ } >+ ); >+ >+ return ( 0, "too_many" ) >+ if not $issuing_rule or $issuing_rule->renewalsallowed <= $issue->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 > DateTime->now( time_zone => C4::Context->tz() ) ) >+ { >+ 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" ); >+ } >+ } >+ > my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); > > # This item can fill one or more unfilled reserve, can those unfilled reserves >@@ -2744,104 +2843,6 @@ sub CanBookBeRenewed { > } > return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found > >- return ( 1, undef ) if $override_limit; >- >- my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); >- my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( >- { categorycode => $patron->categorycode, >- itemtype => $item->effective_itemtype, >- branchcode => $branchcode >- } >- ); >- >- return ( 0, "too_many" ) >- if not $issuing_rule or $issuing_rule->renewalsallowed <= $issue->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 > DateTime->now( time_zone => C4::Context->tz() ) ) >- { >- 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 ); > } > >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19014
:
65590
|
86960
|
90509
|
95348
|
95851
|
95852
|
96688
|
96689
|
97374
|
97395
|
97396
|
97397
|
98704
|
98705
|
98706
|
98717
|
98718
|
98719
|
98720
|
100180