LP#1670407 Lost checkin re-opens transaction
authorBill Erickson <berickxx@gmail.com>
Tue, 28 Mar 2017 18:15:44 +0000 (14:15 -0400)
committerDan Wells <dbw2@calvin.edu>
Tue, 18 Apr 2017 15:05:04 +0000 (11:05 -0400)
Avoid re-closing a circulation that was re-opened during checkin because
it acquired a non-zero balance.  This is typically caused by, for
example, voiding a lost item fee during checkin and/or generating
overdues for lost-then-found items.

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

index 6c035a8..e12828c 100644 (file)
@@ -3332,16 +3332,34 @@ sub checkin_handle_circ_start {
 
 sub checkin_handle_circ_finish {
     my $self = shift;
+    my $e = $self->editor;
     my $circ = $self->circ;
 
-    # see if there are any fines owed on this circ.  if not, close it
-    my ($obt) = $U->fetch_mbts($circ->id, $self->editor);
-    $circ->xact_finish('now') if( $obt and $obt->balance_owed == 0 );
+    # Do one last check before the final circulation update to see 
+    # if the xact_finish value should be set or not.
+    #
+    # The underlying money.billable_xact may have been updated to
+    # reflect a change in xact_finish during checkin bills handling, 
+    # however we can't simply refresh the circulation from the DB,
+    # because other changes may be pending.  Instead, reproduce the
+    # xact_finish check here.  It won't hurt to do it again.
 
-    $logger->debug("circulator: ".$obt->balance_owed." is owed on this circulation");
+    my $sum = $e->retrieve_money_billable_transaction_summary($circ->id);
+    if ($sum) { # is this test still needed?
 
-    return $self->bail_on_events($self->editor->event)
-        unless $self->editor->update_action_circulation($circ);
+        my $balance = $sum->balance_owed;
+
+        if ($balance == 0) {
+            $circ->xact_finish('now');
+        } else {
+            $circ->clear_xact_finish;
+        }
+
+        $logger->info("circulator: $balance is owed on this circulation");
+    }
+
+    return $self->bail_on_events($e->event)
+        unless $e->update_action_circulation($circ);
 
     return undef;
 }