[open-ils-commits] r12754 - trunk/Open-ILS/src/support-scripts/test-scripts (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Apr 1 15:44:36 EDT 2009


Author: erickson
Date: 2009-04-01 15:44:31 -0400 (Wed, 01 Apr 2009)
New Revision: 12754

Modified:
   trunk/Open-ILS/src/support-scripts/test-scripts/print_po.pl
Log:
updated to use trigger for generating templated output

Modified: trunk/Open-ILS/src/support-scripts/test-scripts/print_po.pl
===================================================================
--- trunk/Open-ILS/src/support-scripts/test-scripts/print_po.pl	2009-04-01 19:15:13 UTC (rev 12753)
+++ trunk/Open-ILS/src/support-scripts/test-scripts/print_po.pl	2009-04-01 19:44:31 UTC (rev 12754)
@@ -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}) {
+my $event = $e->retrieve_action_trigger_event(
+    [
+        $event_id, 
+        {flesh => 1, flesh_fields => {atev => ['template_output', 'error_output']}}
+    ]
+);
 
-    print "Lineitem:------------------\n";
-    for my $li_attr (@{$li->attributes}) {
-        print "  " . $li_attr->attr_name . ': ' . $li_attr->attr_value . "\n";
-    }
-
-    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";
+}
 



More information about the open-ils-commits mailing list