method for creating/running format related lineitem events, modeled off the one for...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 12 Feb 2010 18:33:22 +0000 (18:33 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 12 Feb 2010 18:33:22 +0000 (18:33 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15525 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm

index bd14d51..de7b661 100644 (file)
@@ -1088,6 +1088,36 @@ sub format_po {
     return $U->fire_object_event(undef, $hook, $po, $po->ordering_agency);
 }
 
+__PACKAGE__->register_method(
+       method => 'format_lineitem',
+       api_name        => 'open-ils.acq.lineitem.format'
+);
+
+sub format_lineitem {
+    my($self, $conn, $auth, $li_id, $format) = @_;
+    my $e = new_editor(authtoken=>$auth);
+    return $e->event unless $e->checkauth;
+
+    my $li = $e->retrieve_acq_lineitem($li_id) or return $e->event;
+
+    my $context_org;
+    if (defined $li->purchase_order) {
+        my $po = $e->retrieve_acq_purchase_order($li->purchase_order) or return $e->die_event;
+        return $e->event unless $e->allowed('VIEW_PURCHASE_ORDER', $po->ordering_agency);
+        $context_org = $po->ordering_agency;
+    } else {
+        my $pl = $e->retrieve_acq_picklist($li->picklist) or return $e->die_event;
+        if($e->requestor->id != $pl->owner) {
+            return $e->event unless
+                $e->allowed('VIEW_PICKLIST', $pl->org_unit, $pl);
+        }
+        $context_org = $pl->org_unit;
+    }
+
+    my $hook = "format.acqli.$format";
+    return $U->fire_object_event(undef, $hook, $li, $context_org);
+}
+
 __PACKAGE__->register_method (
     method        => 'po_events',
     api_name    => 'open-ils.acq.purchase_order.events.owner',