From: Jeff Davis <jdavis@sitka.bclibraries.ca>
Date: Thu, 1 Nov 2018 23:29:36 +0000 (-0700)
Subject: LP#1801191: ensure recall does not extend due date
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9c90558644e7154a0a68505f719c698f1826954d;p=evergreen%2Fjoelewis.git

LP#1801191: ensure recall does not extend due date

Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
---

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
index 872b78d795..4af8dae616 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm
@@ -1675,6 +1675,8 @@ sub process_recall {
         my $circ = $circs->[0];
         $log->info("Recalling circ ID : " . $circ->id);
 
+        my $old_due_date = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->due_date))->iso8601();
+
         # Give the user a new due date of either a full recall threshold,
         # or the return interval, whichever is further in the future
         my $threshold_date = DateTime::Format::ISO8601->parse_datetime(clean_ISO8601($circ->xact_start))->add(seconds => interval_to_seconds($recall_threshold))->iso8601();
@@ -1682,6 +1684,12 @@ sub process_recall {
             $return_date = $threshold_date;
         }
 
+        # But if the new due date is later than the old one,
+        # keep the old one.
+        if (DateTime->compare(DateTime::Format::ISO8601->parse_datetime($return_date), DateTime::Format::ISO8601->parse_datetime($old_due_date)) == 1) {
+            $return_date = $old_due_date;
+        }
+
         my $update_fields = {
             due_date => $return_date,
             renewal_remaining => 0,
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm
index a42638c806..957fb25a8b 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/HoldTargeter.pm
@@ -1181,6 +1181,8 @@ sub process_recalls {
 
     $self->log_hold("recalling circ ".$circ->id);
 
+    my $old_due_date = DateTime::Format::ISO8601->parse_datetime(cleanse_ISO8601($circ->due_date))->iso8601();
+
     # Give the user a new due date of either a full recall threshold,
     # or the return interval, whichever is further in the future.
     my $threshold_date = DateTime::Format::ISO8601
@@ -1197,6 +1199,14 @@ sub process_recalls {
         $return_date = $threshold_date;
     }
 
+    # But if the new due date is later than the old one,
+    # keep the old one.
+    if (DateTime->compare(
+        DateTime::Format::ISO8601->parse_datetime($return_date),
+        DateTime::Format::ISO8601->parse_datetime($old_due_date)) == 1) { 
+        $return_date = $old_due_date;
+    }
+
     my %update_fields = (
         due_date => $return_date,
         renewal_remaining => 0,