LP#1198465 Stop using storage wrapper for generate_fines()
authorDan Wells <dbw2@calvin.edu>
Fri, 5 Dec 2014 18:57:12 +0000 (13:57 -0500)
committerDan Wells <dbw2@calvin.edu>
Mon, 8 Dec 2014 14:38:43 +0000 (09:38 -0500)
With pieces now in place, let's stop using the storage wrapper for
generate_fines() and call the code directly.

Also, to avoid potential confusion, rename the calling function in
Circulate.pm from generate_fines() to handle_fines().  This function
may also be taking on more than just fine generation in the near future.

Finally, since the new generate_fines() expects one or more pre-filtered
circ objects, add the requisite stop_fines check to handle_fines().

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm

index bc939d2..d9d89b9 100644 (file)
@@ -2107,7 +2107,7 @@ sub do_reservation_return {
         $self->reservation($reservation);
     }
 
-    $self->generate_fines(1);
+    $self->handle_fines(1);
     $self->reservation->return_time('now');
     $self->update_reservation();
     $self->reshelve_copy if $self->copy;
@@ -2526,7 +2526,7 @@ sub do_checkin {
         }
 
         # run the fine generator against this circ
-        $self->generate_fines(undef, $ignore_stop_fines);
+        $self->handle_fines(undef, $ignore_stop_fines);
     }
 
     if( $self->checkin_check_holds_shelf() ) {
@@ -3336,7 +3336,7 @@ sub put_hold_on_shelf {
 
 
 
-sub generate_fines {
+sub handle_fines {
    my $self = shift;
    my $reservation = shift;
    my $ignore_stop_fines = shift;
@@ -3344,6 +3344,8 @@ sub generate_fines {
 
    my $obj = $reservation ? $self->reservation : $self->circ;
 
+   return undef if (!$ignore_stop_fines and $obj->stop_fines);
+
    # If we have a grace period
    if($obj->can('grace_period')) {
       # Parse out the due date
@@ -3354,15 +3356,7 @@ sub generate_fines {
       return undef if ($due_date > DateTime->now);
    }
 
-   if (!exists($self->{_gen_fines_req})) {
-      $self->{_gen_fines_req} = OpenSRF::AppSession->create('open-ils.storage') 
-          ->request(
-             'open-ils.storage.action.circulation.overdue.generate_fines',
-             $obj->id, $ignore_stop_fines
-          );
-   }
-   $self->{_gen_fines_req}->wait_complete;
-   delete($self->{_gen_fines_req});
+   $CC->generate_fines({circs => [$obj], editor => $self->editor});
 
    # refresh the circ in case the fine generator set the stop_fines field
    $self->reservation($self->editor->retrieve_booking_reservation($id)) if $reservation;
@@ -3803,7 +3797,7 @@ sub do_renew {
     }
 
     # Run the fine generator against the old circ
-    $self->generate_fines;
+    $self->do_generate_fines;
 
     $self->run_renew_permit;