[open-ils-commits] r12796 - in trunk/Open-ILS/src/perlmods/OpenILS/Application: . Acq (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Apr 6 10:43:57 EDT 2009
Author: erickson
Date: 2009-04-06 10:43:55 -0400 (Mon, 06 Apr 2009)
New Revision: 12796
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
Log:
moved generic object/event firing to apputils function. plugged in PO formatting call
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm 2009-04-06 13:15:39 UTC (rev 12795)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm 2009-04-06 14:43:55 UTC (rev 12796)
@@ -1072,5 +1072,23 @@
}
+__PACKAGE__->register_method(
+ method => 'format_po',
+ api_name => 'open-ils.acq.purchase_order.format'
+);
+
+sub format_po {
+ my($self, $conn, $auth, $po_id, $format) = @_;
+ my $e = new_editor(authtoken=>$auth);
+ return $e->event unless $e->checkauth;
+
+ my $po = $e->retrieve_acq_purchase_order($po_id) or return $e->event;
+ return $e->event unless $e->allowed('VIEW_PURCHASE_ORDER', $po->ordering_agency);
+
+ my $hook = "format.po.$format";
+ return $U->fire_object_event(undef, $hook, $po, $po->ordering_agency);
+}
+
+
1;
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2009-04-06 13:15:39 UTC (rev 12795)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/AppUtils.pm 2009-04-06 14:43:55 UTC (rev 12796)
@@ -1469,5 +1469,59 @@
return $loc->[0]->{billing_location};
}
+
+# If an event_def ID is not provided, use the hook and context org to find the
+# most appropriate event. create the event, fire it, then return the resulting
+# event with fleshed template_output and error_output
+sub fire_object_event {
+ my($self, $event_def, $hook, $object, $context_org) = @_;
+
+ my $e = OpenILS::Utils::CStoreEditor->new;
+ my $def;
+
+ if($event_def) {
+ $def = $e->retrieve_action_trigger_event_definition($event_def)
+ or return $e->event;
+
+ } else {
+ # find the most appropriate event def depending on context org
+ my $orgs = $self->get_org_ancestors($context_org);
+ $orgs = $e->search_actor_org_unit(
+ [{id => $orgs}, {flesh => 1, flesh_fields => {aou => ['ou_type']}}]);
+ $orgs = [ sort { $a->ou_type->depth cmp $b->ou_type->depth } @$orgs ];
+
+ for my $org (reverse @$orgs) {
+ $def = $e->search_action_trigger_event_definition(
+ {hook => $hook, owner => $org->id}
+ )->[0];
+ last if $def;
+ }
+
+ return $e->event unless $def;
+ }
+
+ my $event_id = $self->simplereq(
+ 'open-ils.trigger',
+ 'open-ils.trigger.event.autocreate.by_definition',
+ $def->id, $object, $context_org);
+
+ my $fire = 'open-ils.trigger.event.fire';
+
+ if($def->group_field) {
+ $fire =~ s/event/event_group/o;
+ $event_id = [$event_id];
+ }
+
+ my $resp = $self->simplereq('open-ils.trigger', $fire, $event_id);
+ return 0 unless $resp and ($resp->{event} or $resp->{events});
+ my $evt = $resp->{event} ? $resp->{event} : $resp->{events}->[0];
+
+ return $e->retrieve_action_trigger_event([
+ $evt->id,
+ {flesh => 1, flesh_fields => {atev => ['template_output', 'error_output']}}
+ ]);
+}
+
+
1;
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm 2009-04-06 13:15:39 UTC (rev 12795)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm 2009-04-06 14:43:55 UTC (rev 12796)
@@ -1084,9 +1084,6 @@
return $e->event unless $e->checkauth;
return $e->event unless $e->allowed('VIEW_CIRCULATIONS');
- my $def = $e->retrieve_action_trigger_event_definition($event_def)
- or return $e->event;
-
my $copy = $e->search_asset_copy({barcode => $barcode, deleted => 'f'})->[0]
or return $e->event;
@@ -1096,26 +1093,7 @@
return undef unless $circ;
- my $event_id = $U->simplereq(
- 'open-ils.trigger',
- 'open-ils.trigger.event.autocreate.by_definition',
- $event_def, $circ, $e->requestor->ws_ou);
-
- my $fire = 'open-ils.trigger.event.fire';
-
- if($def->group_field) {
- $fire =~ s/event/event_group/o;
- $event_id = [$event_id];
- }
-
- my $resp = $U->simplereq('open-ils.trigger', $fire, $event_id);
- return 0 unless $resp and ($resp->{event} or $resp->{events});
- my $evt = $resp->{event} ? $resp->{event} : $resp->{events}->[0];
-
- return $e->retrieve_action_trigger_event([
- $evt->id,
- {flesh => 1, flesh_fields => {atev => ['template_output', 'error_output']}}
- ]);
+ return $U->fire_object_event($event_def, undef, $circ, $e->requestor->ws_ou)
}
More information about the open-ils-commits
mailing list