Removed up-front creation of BAD_PARAMS to prevent compile-time warnings
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 19 Feb 2008 14:25:48 +0000 (14:25 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 19 Feb 2008 14:25:48 +0000 (14:25 +0000)
added some initial purchase order an po_lineitem creation code, needs work

git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8773 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 9c5c342..59825d2 100644 (file)
@@ -1,5 +1,5 @@
 package OpenILS::Application::Acq::Financials;
-use base qw/OpenILS::Application::Acq/;
+use base qw/OpenILS::Application/;
 use strict; use warnings;
 
 use OpenSRF::Utils::Logger qw(:logger);
@@ -11,9 +11,6 @@ use OpenILS::Event;
 use OpenILS::Application::AppUtils;
 my $U = 'OpenILS::Application::AppUtils';
 
-my $BAD_PARAMS = OpenILS::Event->new('BAD_PARAMS');
-
-
 # ----------------------------------------------------------------------------
 # Funding Sources
 # ----------------------------------------------------------------------------
@@ -122,7 +119,8 @@ sub retrieve_org_funding_sources {
     return $e->event unless $e->checkauth;
 
     my $limit_perm = ($$options{limit_perm}) ? $$options{limit_perm} : 'ADMIN_FUNDING_SOURCE';
-    return $BAD_PARAMS unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUNDING_SOURCE/;
+    return OpenILS::Event->new('BAD_PARAMS') 
+        unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUNDING_SOURCE/;
 
     my $org_ids = ($org_id_list and @$org_id_list) ? $org_id_list :
         $U->find_highest_work_orgs($e, $limit_perm, {descendants =>1});
@@ -287,7 +285,8 @@ sub retrieve_org_funds {
     return $e->event unless $e->checkauth;
 
     my $limit_perm = ($$options{limit_perm}) ? $$options{limit_perm} : 'ADMIN_FUND';
-    return $BAD_PARAMS unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUND/;
+    return OpenILS::Event->new('BAD_PARAMS') 
+        unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUND/;
 
     my $org_ids = ($org_id_list and @$org_id_list) ? $org_id_list :
         $U->find_highest_work_orgs($e, $limit_perm, {descendants =>1});
@@ -460,7 +459,7 @@ __PACKAGE__->register_method(
     }
 );
 
-sub retrieve_fund_alloc {
+sub retrieve_funding_source_allocations {
     my($self, $conn, $auth, $fund_alloc_id) = @_;
     my $e = new_editor(authtoken=>$auth);
     return $e->event unless $e->checkauth;
@@ -476,9 +475,6 @@ sub retrieve_fund_alloc {
     return $fund_alloc;
 }
 
-
-
-
 # ----------------------------------------------------------------------------
 # Currency
 # ----------------------------------------------------------------------------
@@ -504,4 +500,97 @@ sub retrieve_all_currency_type {
 }
 
 
+# ----------------------------------------------------------------------------
+# Purchase Orders
+# ----------------------------------------------------------------------------
+
+__PACKAGE__->register_method(
+       method => 'create_purchase_order',
+       api_name        => 'open-ils.acq.purchase_order.create',
+       signature => {
+        desc => 'Creates a new purchase order',
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'purchase_order to create', type => 'object'}
+        ],
+        return => {desc => 'The purchase order id, Event on failure'}
+    }
+);
+
+sub create_purchase_order {
+    my($self, $conn, $auth, $p_order) = @_;
+    my $e = new_editor(xact=>1, authtoken=>$auth);
+    return $e->die_event unless $e->checkauth;
+    $p_order->owner($e->requestor->id);
+
+    if($p_order->default_fund) {
+        # if a default fund is provided, make sure the requestor
+        # actually has permission to spend from that fund
+        my $fund = $e->retrieve_acq_fund($p_order->default_fund)
+            or return $e->die_event;
+        return $e->die_event unless $e->allowed('MANAGE_FUND', $fund->org, $fund);
+    } 
+
+    my $provider = $e->retrieve_acq_provider($p_order->provider)
+        or return $e->die_event;
+
+    return $e->die_event unless $e->allowed('MANAGE_PROVIDER', $provider->owner, $provider);
+
+    $e->create_acq_purchase_order($p_order) or return $e->die_event;
+    $e->commit;
+    return $p_order->id;
+}
+
+
+__PACKAGE__->register_method(
+       method => 'create_po_lineitem',
+       api_name        => 'open-ils.acq.po_lineitem.create',
+       signature => {
+        desc => 'Creates a new purchase order line item',
+        params => [
+            {desc => 'Authentication token', type => 'string'},
+            {desc => 'purchase order line item to create', type => 'object'}
+        ],
+        return => {desc => 'The purchase order line item id, Event on failure'}
+    }
+);
+
+sub create_po_lineitem {
+    my($self, $conn, $auth, $po_li, $options) = @_;
+    my $e = new_editor(xact=>1, authtoken=>$auth);
+    return $e->die_event unless $e->checkauth;
+
+    my $po = $e->retrieve_acq_purchase_order($po_li->purchase_order)
+        or return $e->die_event;
+
+    return OpenILS::Event->new('BAD_PARAMS') 
+        unless $e->requestor->id == $po->owner;
+
+    if($$options{picklist_entry}) {
+        # if a picklist_entry ID is provided, use that as the basis for this item
+        my $ple = $e->retrieve_acq_picklist_entry($$options{picklist_entry})
+            or return $e->die_event;
+        $po_li->marc($ple->marc);
+        $po_li->eg_bib_id($ple->eg_bib_id);
+    }
+
+    if($po_li->fund) {
+        # check fund perms if using the non-default fund
+        my $fund = $e->retrieve_acq_fund($po_li->fund)
+            or return $e->die_event;
+        return $e->die_event unless $e->allowed('MANAGE_FUND', $fund->org, $fund);
+    }
+
+    my $provider = $e->retrieve_acq_provider($po->provider)
+        or return $e->die_event;
+
+    return $e->die_event unless $e->allowed('MANAGE_PROVIDER', $provider->owner, $provider);
+
+    $e->create_acq_po_lineitem($po_li) or return $e->die_event;
+    return $po_li->id;
+}
+
+
+
+
 1;
index 77ef201..8309d69 100644 (file)
@@ -1,5 +1,5 @@
 package OpenILS::Application::Acq::Picklist;
-use base qw/OpenILS::Application::Acq/;
+use base qw/OpenILS::Application/;
 use strict; use warnings;
 
 use OpenSRF::Utils::Logger qw(:logger);
@@ -9,8 +9,6 @@ use OpenILS::Const qw/:const/;
 use OpenSRF::Utils::SettingsClient;
 use OpenILS::Event;
 
-my $BAD_PARAMS = OpenILS::Event->new('BAD_PARAMS');
-
 
 __PACKAGE__->register_method(
        method => 'create_picklist',
@@ -30,7 +28,8 @@ sub create_picklist {
     my $e = new_editor(xact=>1, authtoken=>$auth);
     return $e->die_event unless $e->checkauth;
     return $e->die_event unless $e->allowed('CREATE_PICKLIST');
-    return $BAD_PARAMS unless $e->requestor->id == $picklist->owner;
+    return OpenILS::Event->new('BAD_PARAMS')
+        unless $e->requestor->id == $picklist->owner;
     $e->create_acq_picklist($picklist) or return $e->die_event;
     $e->commit;
     return $picklist->id;
@@ -58,7 +57,7 @@ sub update_picklist {
     # don't let them change the owner
     my $o_picklist = $e->retrieve_acq_picklist($picklist->id)
         or return $e->die_event;
-    return $BAD_PARAMS if (
+    return OpenILS::Event->new('BAD_PARAMS') if (
         $o_picklist->owner != $picklist->owner or
         $picklist->owner != $e->requestor->id );
 
@@ -92,7 +91,11 @@ sub retrieve_picklist {
     $picklist->entry_count(retrieve_picklist_entry_count($e, $picklist_id))
         if $$options{flesh_entry_count};
 
-    return $BAD_PARAMS unless $e->requestor->id == $picklist->owner;
+    if($e->requestor->id != $picklist->owner) {
+        return $e->event unless 
+            $e->allowed('VIEW_PICKLIST', undef, $picklist);
+    }
+
     return $picklist;
 }
 
@@ -237,7 +240,8 @@ sub delete_picklist {
     my $picklist = $e->retrieve_acq_picklist($picklist_id)
         or return $e->die_event;
     # don't let anyone delete someone else's picklist
-    return $BAD_PARAMS if $picklist->owner != $e->requestor->id;
+    return OpenILS::Event->new('BAD_PARAMS')
+        if $picklist->owner != $e->requestor->id;
 
     $e->delete_acq_picklist($picklist) or return $e->die_event;
     $e->commit;
@@ -270,7 +274,8 @@ sub create_picklist_entry {
 
     my $picklist = $e->retrieve_acq_picklist($entry->picklist)
         or return $e->die_event;
-    return $BAD_PARAMS unless $picklist->owner == $e->requestor->id;
+    return OpenILS::Event->new('BAD_PARAMS') 
+        unless $picklist->owner == $e->requestor->id;
 
     # indicate the picklist was updated
     $picklist->edit_time('now');
@@ -315,7 +320,8 @@ sub retrieve_picklist_entry {
     my $picklist = $e->retrieve_acq_picklist($pl_entry->picklist)
         or return $e->event;
 
-    return $BAD_PARAMS if $picklist->owner != $e->requestor->id;
+    return OpenILS::Event->new('BAD_PARAMS') 
+        if $picklist->owner != $e->requestor->id;
     return $pl_entry;
 }
 
@@ -346,7 +352,8 @@ sub delete_picklist_entry {
         or return $e->die_event;
 
     # don't let anyone delete someone else's picklist entry
-    return $BAD_PARAMS if $picklist->owner != $e->requestor->id;
+    return OpenILS::Event->new('BAD_PARAMS') 
+        if $picklist->owner != $e->requestor->id;
 
     $e->delete_acq_picklist_entry($pl_entry) or return $e->die_event;
     $e->commit;
@@ -381,7 +388,8 @@ sub update_picklist_entry {
     ]) or return $e->die_event;
 
     # don't let anyone update someone else's picklist entry
-    return $BAD_PARAMS if $orig_entry->picklist->owner != $e->requestor->id;
+    return OpenILS::Event->new('BAD_PARAMS') 
+        if $orig_entry->picklist->owner != $e->requestor->id;
 
     $e->update_acq_picklist_entry($pl_entry) or return $e->die_event;
     $e->commit;
index 27b5fd3..3e81b5e 100644 (file)
@@ -1,5 +1,5 @@
 package OpenILS::Application::Acq::Provider;
-use base qw/OpenILS::Application::Acq/;
+use base qw/OpenILS::Application/;
 use strict; use warnings;
 
 use OpenILS::Event;
@@ -11,8 +11,6 @@ use OpenSRF::Utils::SettingsClient;
 use OpenILS::Application::AppUtils;
 
 my $U = 'OpenILS::Application::AppUtils';
-my $BAD_PARAMS = OpenILS::Event->new('BAD_PARAMS');
-
 
 __PACKAGE__->register_method(
        method => 'create_provider',
@@ -87,7 +85,8 @@ sub retrieve_org_providers {
 
     my $limit_perm = ($$options{limit_perm}) ? $$options{limit_perm} : 'ADMIN_PROVIDER';
 
-    return $BAD_PARAMS unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_PROVIDER/;
+    return OpenILS::Event->new('BAD_PARAMS')
+        unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_PROVIDER/;
 
     my $org_ids = ($org_id_list and @$org_id_list) ? $org_id_list :
         $U->find_highest_work_orgs($e, $limit_perm, {descendants =>1});