creation method for new user requests, and fix to IDL
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 11 Mar 2010 18:16:11 +0000 (18:16 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 11 Mar 2010 18:16:11 +0000 (18:16 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15801 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm

index a903687..e9dc977 100644 (file)
@@ -4383,7 +4383,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        </class>
 
        <class id="aur" controller="open-ils.cstore open-ils.reporter-store open-ils.pcrud" oils_obj:fieldmapper="acq::user_request" oils_persist:tablename="acq.user_request" reporter:label="User Purchase Request">
-               <fields oils_persist:primary="id">
+               <fields oils_persist:primary="id" oils_persist:sequence="acq.user_request_id_seq">
                        <field reporter:label="ID" name="id" reporter:datatype="id" reporter:selector='label'/>
                        <field reporter:label="User" name="usr" reporter:datatype="link" />
                        <field reporter:label="Request Type" name="request_type" reporter:datatype="link" />
index 25a2a88..a041d24 100644 (file)
@@ -2314,4 +2314,50 @@ sub update_user_request {
     return {complete => 1};
 }
 
+__PACKAGE__->register_method (
+    method      => 'new_user_request',
+    api_name    => 'open-ils.acq.user_request.create'
+);
+
+sub new_user_request {
+    my($self, $conn, $auth, $form_data) = @_;
+    my $e = new_editor(xact => 1, authtoken => $auth);
+    return $e->die_event unless $e->checkauth;
+    my $rid = $e->requestor->id;
+    my $target_user_fleshed;
+    if (! defined $$form_data{'usr'}) {
+        $$form_data{'usr'} = $rid;
+    }
+    if ($$form_data{'usr'} != $rid) {
+        # See if the requestor can place the request on behalf of a different user.
+        $target_user_fleshed = $e->retrieve_actor_user($$form_data{'usr'}) or return $e->die_event;
+        $e->allowed('user_request.create', $target_user_fleshed->home_ou) or return $e->die_event;
+    } else {
+        $target_user_fleshed = $e->requestor;
+        $e->allowed('CREATE_PURCHASE_REQUEST') or return $e->die_event;
+    }
+    if (! defined $$form_data{'pickup_lib'}) {
+        if ($target_user_fleshed->ws_ou) {
+            $$form_data{'pickup_lib'} = $target_user_fleshed->ws_ou;
+        } else {
+            $$form_data{'pickup_lib'} = $target_user_fleshed->home_ou;
+        }
+    }
+    if (! defined $$form_data{'request_type'}) {
+        $$form_data{'request_type'} = 1; # Books
+    }
+    my $aur_obj = new Fieldmapper::acq::user_request; 
+    $aur_obj->isnew(1);
+    $aur_obj->usr( $$form_data{'usr'} );
+    $aur_obj->request_date( 'now' );
+    for my $field ( keys %$form_data ) {
+        if (defined $$form_data{$field} and $field !~ /^(id|lineitem|eg_bib|request_date|cancel_reason)$/) {
+            $aur_obj->$field( $$form_data{$field} );
+        }
+    }
+
+    return ($e->create_acq_user_request($aur_obj) or $e->die_event);
+}
+
+
 1;