From 0120746cf09b68cc10ccc17e0e1e4f3e64b356a9 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 28 Mar 2017 14:15:44 -0400 Subject: [PATCH] LP#1670407 Lost checkin re-opens transaction 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 Signed-off-by: Dan Wells --- .../lib/OpenILS/Application/Circ/Circulate.pm | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm index fb71a23e02..298efbc366 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -3328,16 +3328,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; } -- 2.43.2