From 0e43880cec2982ea201100463fa1237b13da10d0 Mon Sep 17 00:00:00 2001 From: phasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4> Date: Thu, 4 Feb 2010 21:13:30 +0000 Subject: [PATCH] Methods for retrieving action_trigger events related to Purchase Orders git-svn-id: svn://svn.open-ils.org/ILS/trunk@15450 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Financials.pm | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm index b5bb788060..5daafb3d83 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm @@ -1029,7 +1029,82 @@ sub format_po { 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; -- 2.11.0