From d0254ff1a1550813c88269955ada9e0279072a6d Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 1 Apr 2009 19:44:31 +0000 Subject: [PATCH] updated to use trigger for generating templated output git-svn-id: svn://svn.open-ils.org/ILS/trunk@12754 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/support-scripts/test-scripts/print_po.pl | 90 +++++++--------------- 1 file changed, 29 insertions(+), 61 deletions(-) diff --git a/Open-ILS/src/support-scripts/test-scripts/print_po.pl b/Open-ILS/src/support-scripts/test-scripts/print_po.pl index e9f73c2868..db8ec6a570 100755 --- a/Open-ILS/src/support-scripts/test-scripts/print_po.pl +++ b/Open-ILS/src/support-scripts/test-scripts/print_po.pl @@ -5,84 +5,52 @@ #---------------------------------------------------------------- require '../oils_header.pl'; +use vars qw/$apputils/; use strict; +use Data::Dumper; my $config = shift; my $username = shift || 'admin'; my $password = shift || 'open-ils'; my $po_id = shift; +my $hook = shift || 'format.po.jedi'; osrf_connect($config); oils_login($username, $password); my $e = OpenILS::Utils::CStoreEditor->new; -my $po = $e->retrieve_acq_purchase_order( - [ - $po_id, - { - flesh => 3, - flesh_fields => { - acqpo => [qw/lineitems ordering_agency provider/], - acqpro => [qw/addresses/], - jub => [qw/attributes lineitem_details/], - acqlid => [qw/fund location owning_lib/], - aou => [qw/mailing_address billing_address/] - } - } - ] -); +my $po = $e->retrieve_acq_purchase_order($po_id) or oils_event_die($e->event); +my $orgs = $apputils->get_org_ancestors($po->ordering_agency); +my $defs = $e->search_action_trigger_event_definition({hook => $hook, owner => $orgs}); +$defs = [sort { $a->id cmp $b->id } @$defs ]; # this is a brittle hack, but.. meh +my $def = pop @$defs; +print "using def " . $def->id . " at org_unit " . $def->owner . "\n"; -die "No PO with id $po_id\n" unless $po; +die "No event_definition found with hook $hook\n" unless $def; +my $event_id = $apputils->simplereq( + 'open-ils.trigger', + 'open-ils.trigger.event.autocreate.by_definition', + $def->id, $po, $po->ordering_agency); -print 'PO ID: ' . $po->id . "\n"; -print 'Ordering Agency: ' . $po->ordering_agency->shortname . "\n"; -if(my $addr = $po->ordering_agency->mailing_address) { - print "Mailing Address: \n"; - print ' street1: ' . $addr->street1 . "\n"; - print ' street2: ' . $addr->street2 . "\n"; - print ' city: ' . $addr->city . "\n"; - print ' county: ' . $addr->county . "\n"; - print ' state: ' . $addr->state . "\n"; - print ' country: ' . $addr->country . "\n"; - print ' post_code: ' . $addr->post_code . "\n"; -} +my $result = $apputils->simplereq( + 'open-ils.trigger', + 'open-ils.trigger.event.fire', $event_id); -if(my $addr = $po->ordering_agency->billing_address) { - print "Billing Address: \n"; - print ' street1: ' . $addr->street1 . "\n"; - print ' street2: ' . $addr->street2 . "\n"; - print ' city: ' . $addr->city . "\n"; - print ' county: ' . $addr->county . "\n"; - print ' state: ' . $addr->state . "\n"; - print ' country: ' . $addr->country . "\n"; - print ' post_code: ' . $addr->post_code . "\n"; -} -print 'Provider: ' . $po->provider->code . "\n"; -if(my $addr = $po->provider->addresses->[0]) { - print "Provider Address:\n"; - print ' street1: ' . $addr->street1 . "\n"; - print ' street2: ' . $addr->street2 . "\n"; - print ' city: ' . $addr->city . "\n"; - print ' county: ' . $addr->county . "\n"; - print ' state: ' . $addr->state . "\n"; - print ' country: ' . $addr->country . "\n"; - print ' post_code: ' . $addr->post_code . "\n"; -} +print "Event state is " . $result->{event}->state . "\n"; -for my $li (@{$po->lineitems}) { - - print "Lineitem:------------------\n"; - for my $li_attr (@{$li->attributes}) { - print " " . $li_attr->attr_name . ': ' . $li_attr->attr_value . "\n"; - } +my $event = $e->retrieve_action_trigger_event( + [ + $event_id, + {flesh => 1, flesh_fields => {atev => ['template_output', 'error_output']}} + ] +); - for my $li_det (@{$li->lineitem_details}) { - print " Copy----------------------\n"; - print " Owning Lib: " . $li_det->owning_lib->shortname . "\n"; - print " Fund: " . $li_det->fund->code . "\n"; - print " Location: " . $li_det->location->name . "\n"; - } +if($event->template_output) { + print $event->template_output->data . "\n"; +} +if($event->error_output) { + print $event->error_output->data . "\n"; } -- 2.11.0