LP#1484989 Don't close xacts with checkin-generated fines
authorDan Wells <dbw2@calvin.edu>
Fri, 14 Aug 2015 19:11:16 +0000 (15:11 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 27 Aug 2015 15:52:15 +0000 (15:52 +0000)
If a transaction has checkin-generated fines, and previously had a
balance of zero, the rearranged billing code was prematurely closing
the transaction.  This commit separates the closing step to run after
any possible fine generation.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/live_t/10-lp1484989_dont_close_fined_xacts.t [new file with mode: 0644]

index f92f5b8..d63cdc8 100644 (file)
@@ -2367,9 +2367,8 @@ sub do_checkin {
     }
 
     if( $self->circ ) {
-        $self->checkin_handle_circ;
+        $self->checkin_handle_circ_start;
         return if $self->bail_out;
-        $self->checkin_changed(1);
 
         if (!$dont_change_lost_zero) {
             # if this circ is LOST and we are configured to generate overdue
@@ -2392,6 +2391,11 @@ sub do_checkin {
             # handle fines for this circ, including overdue gen if needed
             $self->handle_fines;
         }
+
+        $self->checkin_handle_circ_finish;
+        return if $self->bail_out;
+        $self->checkin_changed(1);
+
     } elsif( $self->transit ) {
         my $hold_transit = $self->process_received_transit;
         $self->checkin_changed(1);
@@ -3224,7 +3228,7 @@ sub handle_fines {
    return undef;
 }
 
-sub checkin_handle_circ {
+sub checkin_handle_circ_start {
    my $self = shift;
    my $circ = $self->circ;
    my $copy = $self->copy;
@@ -3272,9 +3276,15 @@ sub checkin_handle_circ {
         $self->update_copy;
     }
 
+    return undef;
+}
+
+sub checkin_handle_circ_finish {
+    my $self = shift;
+    my $circ = $self->circ;
 
     # see if there are any fines owed on this circ.  if not, close it
-    ($obt) = $U->fetch_mbts($circ->id, $self->editor);
+    my ($obt) = $U->fetch_mbts($circ->id, $self->editor);
     $circ->xact_finish('now') if( $obt and $obt->balance_owed == 0 );
 
     $logger->debug("circulator: ".$obt->balance_owed." is owed on this circulation");
diff --git a/Open-ILS/src/perlmods/live_t/10-lp1484989_dont_close_fined_xacts.t b/Open-ILS/src/perlmods/live_t/10-lp1484989_dont_close_fined_xacts.t
new file mode 100644 (file)
index 0000000..0a4aa56
--- /dev/null
@@ -0,0 +1,36 @@
+#!perl
+
+use Test::More tests => 2;
+
+diag("Make sure we don't close xacts with fines");
+
+use strict;
+use warnings;
+
+use OpenILS::Utils::TestUtils;
+my $script = OpenILS::Utils::TestUtils->new();
+#our $apputils   = "OpenILS::Application::AppUtils";
+my $storage_ses = $script->session('open-ils.storage');
+$script->authenticate({
+    username => 'admin',
+    password => 'demo123',
+    type => 'staff'});
+ok( $script->authtoken, 'Have an authtoken');
+
+my $barcode = 'CONC4000054';
+my $circ_id = 18;
+
+my $checkin_resp = $script->do_checkin_override({
+    barcode => $barcode});
+
+my $circ_req = $storage_ses->request('open-ils.storage.direct.action.circulation.retrieve', $circ_id);
+if (my $circ_resp = $circ_req->recv) {
+    if (my $circ = $circ_resp->content) {
+        ok(
+            !$circ->xact_finish,
+            'Circ with id = ' . $circ_id . ' is overdue with fines, so xact_finish isn\'t set'
+        );
+    }
+}
+
+$script->logout();