Use xact_start for due date calc instead of now collab/dyrcona/lp1222240-due-date-from-xact_start
authorThomas Berezansky <tsbere@mvlc.org>
Mon, 9 Sep 2013 19:49:47 +0000 (15:49 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Thu, 26 Sep 2013 19:11:43 +0000 (15:11 -0400)
If you don't supply a due date when creating a circulation with the
open-ils.circ.checkout family of calls, the due date is currently
calculated from now().  This code modification changes that so that
if a checkout_date is supplied that is used to calculate the due date
instead of now().

This enables some interesting uses of the open-ils.circ module for
batch circulation in the cases of offline use from a spreadsheet and
not the offline client or in the case of migrating circulations from
another ILS into Evergreen.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

index b390688..36f8a87 100644 (file)
@@ -2042,7 +2042,7 @@ sub build_checkout_circ_object {
 
     # if a patron is renewing, 'requestor' will be the patron
     $circ->circ_staff($self->editor->requestor->id);
-    $circ->due_date( $self->create_due_date($circ->duration, $duration_date_ceiling, $duration_date_ceiling_force) ) if $circ->duration;
+    $circ->due_date( $self->create_due_date($circ->duration, $duration_date_ceiling, $duration_date_ceiling_force, $circ->xact_start) ) if $circ->duration;
 
     $self->circ($circ);
 }
@@ -2250,7 +2250,7 @@ sub apply_modified_due_date {
 
 
 sub create_due_date {
-    my( $self, $duration, $date_ceiling, $force_date ) = @_;
+    my( $self, $duration, $date_ceiling, $force_date, $start_time ) = @_;
 
     # if there is a raw time component (e.g. from postgres), 
     # turn it into an interval that interval_to_seconds can parse
@@ -2258,6 +2258,7 @@ sub create_due_date {
 
     # for now, use the server timezone.  TODO: use workstation org timezone
     my $due_date = DateTime->now(time_zone => 'local');
+    $due_date = DateTime::Format::ISO8601->new->parse_datetime(cleanse_ISO8601($start_time)) if $start_time;
 
     # add the circ duration
     $due_date->add(seconds => OpenSRF::Utils->interval_to_seconds($duration));