From: Jason Stephenson Date: Wed, 15 Jan 2014 19:43:38 +0000 (-0500) Subject: Make real_void_bills accept an editor argument instead of authtoken. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0996ba038300c647351d52647862134bc678131e;p=working%2FEvergreen.git Make real_void_bills accept an editor argument instead of authtoken. This makes its caller responsible for handling a database transaction and prevents no transaction errors in cases where we have already started a database transaction. This commit also eliminates the unvoid_bills function that is no longer used anywhere in the code. Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm index 77a4748d21..8acaf363cd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm @@ -62,7 +62,7 @@ sub void_overdues { my $billids = $e->search_money_billing([$bill_search, {idlist=>1}]); if ($billids && @$billids) { - my $result = $class->real_void_bills($e->authtoken, $billids, $note); + my $result = $class->real_void_bills($e, $billids, $note); if (ref($result)) { return $result; } @@ -93,7 +93,7 @@ sub void_bills_of_type { ); if ($bills && @$bills) { - my $result = $class->real_void_bills($e->authtoken, $bills, $note); + my $result = $class->real_void_bills($e, $bills, $note); if (ref($result)) { return $result; } @@ -102,44 +102,6 @@ sub void_bills_of_type { return undef; } -# ------------------------------------------------------------------ -# "Unvoids" a given bill. Basically, we create a new bill equal to -# the amount voided on the original bill. -# -# Takes an authtoken, the bill object whose voids you want to undo, and -# an optional note. -# -# Returns undef on success or an event on failure. -# ------------------------------------------------------------------ -sub unvoid_bill { - my ($class, $authtoken, $bill, $note) = @_; - - # Get and editor, check for a session, and check that we can void - # bills. (If we can void bills, we can unvoid them, too.) - my $e = new_editor (authtoken => $authtoken, xact => 1); - return $e->die_event unless $e->checkauth; - return $e->die_event unless $e->allowed('VOID_BILLING'); - - my $voids = $e->search_money_void_payment( - { - billing => $bill->id() - } - ); - - if ($voids && @$voids) { - my $void_total = 0; - map {$void_total += $_->amount()} @$voids; - my $result = $class->create_bill($e, $void_total, $bill->btype(), $bill->billing_type(), $bill->xact(), $note); - if ($result) { - $e->rollback(); - return $result; - } - $e->commit; - } - - return undef; -} - sub reopen_xact { my($class, $e, $xactid) = @_; @@ -504,13 +466,12 @@ sub bill_payment_map_for_xact { } -# This subroutine actually handles voiding of bills. It takes an -# authtoken, an arrayref of bill ids or bills, and an optional note. +# This subroutine actually handles voiding of bills. It takes a +# CStoreEditor, an arrayref of bill ids or bills, and an optional note. sub real_void_bills { - my ($class, $authtoken, $billids, $note) = @_; + my ($class, $e, $billids, $note) = @_; - # Get an editor and see if we have permission to void bills. - my $e = new_editor( authtoken => $authtoken, xact => 1 ); + # Get with the editor to see if we have permission to void bills. return $e->die_event unless $e->checkauth; return $e->die_event unless $e->allowed('VOID_BILLING'); @@ -618,7 +579,6 @@ sub real_void_bills { # made it impossible to void an already voided bill, so # we're doing the same. if ($amount_to_void <= 0) { - $e->rollback; return OpenILS::Event->new('BILL_ALREADY_VOIDED', payload => $bill); } @@ -683,7 +643,7 @@ sub real_void_bills { OpenILS::Utils::Penalty->calculate_penalties($e, $user_id, $org_id); } } - $e->commit; + return 1; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm index 31f21bbc57..a7db19ac22 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Money.pm @@ -754,7 +754,16 @@ __PACKAGE__->register_method( ); sub void_bill { my( $s, $c, $authtoken, @billids ) = @_; - return $CC->real_void_bills($authtoken, \@billids); + my $editor = new_editor(auth=>$authtoken, xact=>1); + my $rv = $CC->real_void_bills($editor, \@billids); + if (ref($rv) eq 'HASH') { + # We got an event. + $editor->rollback(); + } else { + # We should have gotten 1. + $editor->commit(); + } + return $rv; }