[open-ils-commits] r15450 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Feb 4 16:13:35 EST 2010


Author: phasefx
Date: 2010-02-04 16:13:30 -0500 (Thu, 04 Feb 2010)
New Revision: 15450

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
Log:
Methods for retrieving action_trigger events related to Purchase Orders

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm	2010-02-04 18:09:07 UTC (rev 15449)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm	2010-02-04 21:13:30 UTC (rev 15450)
@@ -1029,7 +1029,82 @@
     return $U->fire_object_event(undef, $hook, $po, $po->ordering_agency);
 }
 
+__PACKAGE__->register_method (
+    method        => 'po_events',
+    api_name    => 'open-ils.acq.purchase_order.events.owner',
+    stream      => 1,
+);
 
+__PACKAGE__->register_method (
+    method        => 'po_events',
+    api_name    => 'open-ils.acq.purchase_order.events.ordering_agency',
+    stream      => 1,
+);
 
+__PACKAGE__->register_method (
+    method        => 'po_events',
+    api_name    => 'open-ils.acq.purchase_order.events.id',
+    stream      => 1,
+);
+
+sub po_events {
+    my($self, $conn, $auth, $search_value, $options) = @_;
+    my $e = new_editor(authtoken => $auth);
+    return $e->event unless $e->checkauth;
+
+    (my $search_field = $self->api_name) =~ s/.*\.([_a-z]+)$/$1/;
+    my $obj_type = 'acqpo';
+
+    my $query = {
+        "select"=>{"atev"=>["id"]}, 
+        "from"=>"atev", 
+        "where"=>{
+            "target"=>{
+                "in"=>{
+                    "select"=>{$obj_type=>["id"]}, 
+                    "from"=>$obj_type,
+                    "where"=>{$search_field=>$search_value}
+                }
+            }, 
+            "state"=>"pending" 
+        }
+    };
+
+    if (defined $options->{state}) {
+        $query->{'where'}{'state'} = $options->{state}
+    }
+
+    if (defined $options->{start_time}) {
+        $query->{'where'}{'start_time'} = $options->{start_time};
+    }
+
+    my $po_events = $e->json_query($query);
+
+    my $flesh_fields = $options->{flesh_fields} || {};
+    my $flesh_depth = $options->{flesh_depth} || 1;
+    $flesh_fields->{atev} = ['event_def'] unless $flesh_fields->{atev};
+
+    for my $id (@$po_events) {
+        my $event = $e->retrieve_action_trigger_event([
+            $id->{id},
+            {flesh => $flesh_depth, flesh_fields => $flesh_fields}
+        ]);
+        if (! $event) { next; }
+
+        my $po = retrieve_purchase_order_impl(
+            $e,
+            $event->target(),
+            {flesh_lineitem_count=>1,flesh_price_summary=>1}
+        );
+
+        if ($e->allowed( ['CREATE_PURCHASE_ORDER','VIEW_PURCHASE_ORDER'], $po->ordering_agency() )) {
+            $event->target( $po );
+            $conn->respond($event);
+        }
+    }
+
+    return undef;
+}
+
 1;
 



More information about the open-ils-commits mailing list