return penalty objects from retrieve_penalties. flesh the event desc with the penalt...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 13 Jan 2009 17:44:05 +0000 (17:44 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 13 Jan 2009 17:44:05 +0000 (17:44 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11814 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
Open-ILS/src/perlmods/OpenILS/Utils/Penalty.pm

index 58ad587..acdef57 100644 (file)
@@ -1110,9 +1110,24 @@ sub patron_adv_search {
        my $e = new_editor(authtoken=>$auth);
        return $e->event unless $e->checkauth;
        return $e->event unless $e->allowed('VIEW_USER');
-       return $U->storagereq(
+
+    my $bcids = [];
+    if(my $bc = $$search_hash{card}{value}) {
+        $bcids = $e->json_query({
+            select => {ac => ['usr']}, 
+            from => {ac => {au => {field => 'id', fkey => 'usr'}}}, 
+            where => {'+ac' => {barcode => {like => "$bc%"}, active => 't'}, '+au' => {deleted => 'f'}}
+        });
+        $bcids = map [ {$_->{usr} ] @$bcids;
+    }
+
+    my $ids = $U->storagereq(
                "open-ils.storage.actor.user.crazy_search", $search_hash, 
             $search_limit, $search_sort, $include_inactive, $e->requestor->ws_ou, $search_depth);
+
+    my %h; # dedup
+    $h{$_} = 1 for (@$bcids, $ids);
+    return [keys %h];
 }
 
 
index ba675b5..f500015 100644 (file)
@@ -1064,18 +1064,6 @@ sub fetch_user_by_barcode {
        
 }
 
-
-# ---------------------------------------------------------------------
-# Updates and returns the patron penalties
-# ---------------------------------------------------------------------
-sub update_patron_penalties_nonblock {
-       my( $self, %args ) = @_;
-       return $self->simplereq(
-               'open-ils.penalty',
-               'open-ils.penalty.patron_penalty.calculate', {background => 1}
-       );
-}
-
 sub fetch_bill {
        my( $self, $billid ) = @_;
        $logger->debug("Fetching billing $billid");
@@ -1085,8 +1073,6 @@ sub fetch_bill {
        return($bill, $evt);
 }
 
-
-
 my $ORG_TREE;
 sub fetch_org_tree {
        my $self = shift;
index 24f7fd8..0fccc00 100644 (file)
@@ -838,7 +838,13 @@ sub run_patron_permit_scripts {
         my $penalties = OpenILS::Utils::Penalty->retrieve_penalties($self->editor, $patronid, $self->circ_lib, $mask);
         $penalties = $penalties->{fatal_penalties};
 
-        push(@allevents, OpenILS::Event->new($_)) for (@$penalties, @$patron_events);
+        for my $pen (@$penalties) {
+            my $event = OpenILS::Event->new($pen->name);
+            $event->{desc} = $pen->label;
+            push(@allevents, $event);
+        }
+
+        push(@allevents, OpenILS::Event->new($_)) for (@$patron_events);
     }
 
     $logger->info("circulator: permit_patron script returned events: @allevents") if @allevents;
index 439b889..2e0119c 100644 (file)
@@ -8,6 +8,7 @@ use OpenILS::Utils::Fieldmapper;
 use OpenILS::Utils::PermitHold;
 use DateTime;
 use DateTime::Format::ISO8601;
+use OpenILS::Penalty;
 
 sub isTrue {
        my $v = shift;
@@ -601,7 +602,6 @@ sub generate_fines {
 
        my %hoo = map { ( $_->id => $_ ) } actor::org_unit::hours_of_operation->retrieve_all;
 
-       my $penalty = OpenSRF::AppSession->create('open-ils.penalty');
        for my $c (@circs) {
        
                try {
@@ -765,13 +765,7 @@ sub generate_fines {
 
                        $self->method_lookup('open-ils.storage.transaction.commit')->run;
 
-                       $penalty->request(
-                               'open-ils.penalty.patron_penalty.calculate',
-                               { patron        => $c->usr->to_fieldmapper,
-                                 update        => 1,
-                                 background    => 1,
-                               }
-                       )->gather(1);
+            OpenILS::Utils::Penalty->calculate_penalties(undef, $c->usr, $c->circ_lib);
 
                } catch Error with {
                        my $e = shift;
index 86a0a34..4b42c4e 100644 (file)
@@ -17,6 +17,12 @@ my $U = "OpenILS::Application::AppUtils";
 sub calculate_penalties {
     my($class, $e, $user_id, $context_org) = @_;
 
+    my $rollback = 0;
+    unless($e) {
+        $e = new_editor(xact =>1);
+        $rollback = 1;
+    }
+
     my $penalties = $e->json_query({from => ['actor.calculate_system_penalties',$user_id, $context_org]});
 
     for my $pen_obj (@$penalties) {
@@ -37,6 +43,7 @@ sub calculate_penalties {
         }
     }
 
+    $e->rollback if $rollback;
     return undef;
 }
 
@@ -56,13 +63,13 @@ sub retrieve_penalties {
         if($p->standing_penalty->block_list) {
             for my $m (@fatal_mask) {
                 if($p->standing_penalty->block_list =~ /$m/) {
-                    push(@fatal, $p->standing_penalty->name);
+                    push(@fatal, $p->standing_penalty);
                     $pushed = 1;
                     last;
                 }
             }
         }
-        push(@info, $p->standing_penalty->name) unless $pushed;
+        push(@info, $p->standing_penalty) unless $pushed;
     }
 
     return {fatal_penalties => \@fatal, info_penalties => \@info};