[open-ils-commits] r19481 - branches/rel_2_1/Open-ILS/src/perlmods/lib/OpenILS/Application (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Feb 18 09:36:12 EST 2011


Author: erickson
Date: 2011-02-18 09:36:10 -0500 (Fri, 18 Feb 2011)
New Revision: 19481

Modified:
   branches/rel_2_1/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Log:
More user transaction retrieval API cleanup

Use consistent xact fleshing mechanism for circulations both for
less/cleaner code and to consistently take advantage of CSToreEditor for
authoritative support.

Added .flesh option to transaction history api calls, consistent with
non-history version.

Added a have_payments history call so we can limit retrieval to xacts
that had at least 1 payment

When making sub-req calls to payment API calls, call .authoritative as
appropriate

Modified: branches/rel_2_1/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
===================================================================
--- branches/rel_2_1/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm	2011-02-18 14:35:06 UTC (rev 19480)
+++ branches/rel_2_1/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm	2011-02-18 14:36:10 UTC (rev 19481)
@@ -1639,7 +1639,7 @@
             }
         }
     );
-    /\.have_balance/ and $args{authoritative} = 1;     # FIXME: I don't know why have_charge isn't authoritative
+    $args{authoritative} = 1;
     __PACKAGE__->register_method(%args);
 }
 
@@ -1680,30 +1680,29 @@
 
 
 sub user_transactions {
-	my( $self, $client, $login_session, $user_id, $type, $options ) = @_;
+	my( $self, $client, $auth, $user_id, $type, $options ) = @_;
     $options ||= {};
 
-	my( $user_obj, $target, $evt ) = $apputils->checkses_requestor(
-		$login_session, $user_id, 'VIEW_USER_TRANSACTIONS' );
-	return $evt if $evt;
+    my $e = new_editor(authtoken => $auth);
+    return $e->event unless $e->checkauth;
 
+    my $user = $e->retrieve_actor_user($user_id) or return $e->event;
+
+    return $e->event unless $e->allowed('VIEW_USER_TRANSACTIONS', $user->home_ou);
+
     my $api = $self->api_name();
 
     my $filter = ($api =~ /have_balance/o) ?
         { 'balance_owed' => { '<>' => 0 } }:
         { 'total_owed' => { '>' => 0 } };
 
-    my ($trans) = $self->method_lookup(
-        'open-ils.actor.user.transactions.history.still_open')
-      ->run( $login_session, $user_id, $type, $filter, $options );
+    my $method = 'open-ils.actor.user.transactions.history.still_open';
+    $method = "$method.authoritative" if $api => /authoritative/;
+    my ($trans) = $self->method_lookup($method)->run($auth, $user_id, $type, $filter, $options);
 
 	if($api =~ /total/o) { 
 		my $total = 0.0;
-		for my $t (@$trans) {
-			$total += $t->balance_owed;
-		}
-
-		$logger->debug("Total balance owed by user $user_id: $total");
+        $total += $_->balance_owed for @$trans;
 		return $total;
 	}
 
@@ -1718,27 +1717,8 @@
 			next;
 		}
 
-		my $circ = $apputils->simple_scalar_request(
-				"open-ils.cstore",
-				"open-ils.cstore.direct.action.circulation.retrieve",
-				$t->id );
-
-		next unless $circ;
-
-		my $title = $apputils->simple_scalar_request(
-			"open-ils.storage", 
-			"open-ils.storage.fleshed.biblio.record_entry.retrieve_by_copy",
-			$circ->target_copy );
-
-		next unless $title;
-
-		my $u = OpenILS::Utils::ModsParser->new();
-		$u->start_mods_batch($title->marc());
-		my $mods = $u->finish_mods_batch();
-		$mods->doc_id($title->id) if $mods;
-
-		push @resp, {transaction => $t, circ => $circ, record => $mods };
-
+        my $circ_data = flesh_circ($e, $t->id);
+		push @resp, {transaction => $t, %$circ_data};
 	}
 
 	return \@resp; 
@@ -1777,8 +1757,18 @@
     return $trans unless $self->api_name =~ /flesh/;
     return {transaction => $trans} if $trans->xact_type ne 'circulation';
 
+    my $circ_data = flesh_circ($e, $trans->id, 1);
+
+	return {transaction => $trans, %$circ_data};
+}
+
+sub flesh_circ {
+    my $e = shift;
+    my $circ_id = shift;
+    my $flesh_copy = shift;
+
     my $circ = $e->retrieve_action_circulation([
-        $trans->id, {
+        $circ_id, {
             flesh => 3,
             flesh_fields => {
                 circ => ['target_copy'],
@@ -1807,7 +1797,7 @@
     $circ->target_copy($circ->target_copy->id);
     $copy->call_number($copy->call_number->id);
 
-	return {transaction => $trans, circ => $circ, record => $mods, copy => $copy };
+	return {circ => $circ, record => $mods, copy => ($flesh_copy) ? $copy : undef };
 }
 
 
@@ -2019,23 +2009,20 @@
     return @sig;
 }
 
-my %hist_methods = (
+my %auth_hist_methods = (
     'history'             => '',
     'history.have_charge' => 'that have an initial charge',
     'history.still_open'  => 'that are not finished',
-);
-my %auth_hist_methods = (
     'history.have_balance'         => 'that have a balance',
     'history.have_bill'            => 'that have billings',
     'history.have_bill_or_payment' => 'that have non-zero-sum billings or at least 1 payment',
+    'history.have_payment' => 'that have at least 1 payment',
 );
-foreach (keys %hist_methods) {
-    __PACKAGE__->register_method(_sigmaker($_,       $hist_methods{$_}));
-    __PACKAGE__->register_method(_sigmaker("$_.ids", $hist_methods{$_}));
-}
+
 foreach (keys %auth_hist_methods) {
     __PACKAGE__->register_method(_sigmaker($_,       $auth_hist_methods{$_}, 1));
     __PACKAGE__->register_method(_sigmaker("$_.ids", $auth_hist_methods{$_}, 1));
+    __PACKAGE__->register_method(_sigmaker("$_.fleshed", $auth_hist_methods{$_}, 1));
 }
 
 sub user_transaction_history {
@@ -2065,6 +2052,10 @@
             'last_payment_ts' => { '<>' => undef }
         };
 
+    } elsif($api =~ /have_payment/) {
+
+        $filter->{last_payment_ts} ||= {'<>' => undef};
+
     } elsif( $api =~ /have_balance/o) {
 
         # transactions that have a non-zero overall balance
@@ -2087,17 +2078,27 @@
     $options_clause->{'offset'} = $options->{'offset'} if $options->{'offset'}; 
 
     my $mbts = $e->search_money_billable_transaction_summary(
-        [ 
-            { usr => $userid, @xact_finish, %$filter },
+        [   { usr => $userid, @xact_finish, %$filter },
             $options_clause
         ]
     );
 
-    if ($api =~ /\.ids/) {
-    	return [map {$_->id} @$mbts];
-    } else {
-        return $mbts;
-    }
+    return [map {$_->id} @$mbts] if $api =~ /\.ids/;
+    return $mbts unless $api =~ /fleshed/;
+
+	my @resp;
+	for my $t (@$mbts) {
+			
+		if( $t->xact_type ne 'circulation' ) {
+			push @resp, {transaction => $t};
+			next;
+		}
+
+        my $circ_data = flesh_circ($e, $t->id);
+		push @resp, {transaction => $t, %$circ_data};
+	}
+
+	return \@resp; 
 }
 
 



More information about the open-ils-commits mailing list