From 1c41f199973d7a034ace3f996ee1b55ec5317981 Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Thu, 24 Mar 2022 11:42:55 +0000
Subject: [PATCH] Bug 29537: Remove unnecessary if-else checks for soonest
 renew date

GetSoonestRenewDate() calculates the renewal due date now also
correctly for auto-renewals after the fixes from bug 29476 so we don't
have to add any if-else checks because of it being buggy anymore.

To test:
 1) prove t/db_dependent/Circulation.t

Signed-off-by: David Nind <david@davidnind.com>
---
 C4/Circulation.pm | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index d0f292650d..abd0a5ca5d 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -4457,23 +4457,12 @@ sub _CanBookBeAutoRenewed {
         }
     }
 
-    if ( defined $issuing_rule->{norenewalbefore}
-        and $issuing_rule->{norenewalbefore} ne "" ) {
-        if ( GetSoonestRenewDate($patron->id, $item->id) > dt_from_string()) {
-            return "auto_too_soon";
-        } else {
-            return "ok";
-        }
-    }
-
-    # Fallback for automatic renewals:
-    # If norenewalbefore is undef, don't renew before due date.
-    my $now = dt_from_string;
-    if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
-        return "ok";
-    } else {
+    if ( GetSoonestRenewDate( $patron->id, $item->id ) > dt_from_string() )
+    {
         return "auto_too_soon";
     }
+
+    return "ok";
 }
 
 sub _item_denied_renewal {
-- 
2.30.2