From f8af9fc2759b2c01e038836c9934663e238ee884 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 6 Oct 2013 17:13:01 -0400 Subject: [PATCH] LP 1198465: Update logic in checkin_handle_lost_or_lo_now_found_restore_od Signed-off-by: Dan Wells Signed-off-by: Kathy Lussier Signed-off-by: Ben Shum --- .../lib/OpenILS/Application/Circ/Circulate.pm | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 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 c11b2131d0..93c288e86c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm @@ -3821,18 +3821,29 @@ sub checkin_handle_lost_or_lo_now_found_restore_od { ); $logger->debug("returning ".scalar(@$ods)." overdue charges pre-$tag"); - for my $bill (@$ods) { - if( $U->is_true($bill->voided) ) { - $logger->info("$tag item returned - restoring overdue ".$bill->id); - $bill->voided('f'); - $bill->clear_void_time; - $bill->voider($self->editor->requestor->id); - my $note = ($bill->note) ? $bill->note . "\n" : ''; - $bill->note("${note}System: $tag RETURNED - OVERDUES REINSTATED"); - - $self->bail_on_events($self->editor->event) - unless $self->editor->update_money_billing($bill); - } + # Because actual users get up to all kinds of unexpectedness, we + # only recreate up to $circ->max_fine in bills. I know you think + # it wouldn't happen that bills could get created, voided, and + # recreated more than once, but I guaran-damn-tee you that it will + # happen. + if ($ods && @$ods) { + my $void_amount = 0; + my $void_max = $self->circ->max_fine(); + my @billings = map {$_->id()} @$ods; + my $voids = $self->editor->search_money_adjustment_payment( + { + billing => \@billings + } + ); + map {$void_amount += $_->amount()} @$voids; + $CC->create_bill( + $self->editor, + ($void_amount < $void_max ? $void_amount : $void_max), + $ods->[0]->btype(), + $ods->[0]->billing_type(), + $self->circ->id(), + "System: $tag RETURNED - OVERDUES REINSTATED" + ); } } -- 2.43.2