Show
Ignore:
Timestamp:
05/16/08 12:18:51 (5 months ago)
Author:
erickson
Message:

Initial code to take a lineitem and create the necessary bib, call_number, and copy objects.
Currently, it's relatively free-form and allows for a lot of options from the client end
Probably need to add some level of user/org settings checking for various bits

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/acq-experiment/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm

    r9623 r9628  
    99use OpenSRF::Utils::SettingsClient; 
    1010use OpenILS::Event; 
     11use OpenILS::Application::AppUtils; 
     12my $U = 'OpenILS::Application::AppUtils'; 
    1113 
    1214 
     
    321323 
    322324__PACKAGE__->register_method( 
     325        method => 'create_lineitem_assets', 
     326        api_name        => 'open-ils.acq.lineitem.assets.create', 
     327        signature => { 
     328        desc => q/Creates the bibliographic data, volume, and copies associated with a lineitem./, 
     329        params => [ 
     330            {desc => 'Authentication token', type => 'string'}, 
     331            {desc => 'The lineitem id', type => 'number'}, 
     332            {desc => q/Options hash.  This contains an object that can be mapped into 
     333                a set of volume and copy objects.  {"volumes":[{"label":"vol1", "owning_lib":4,"copies":[{"barcode":"123"},...]}, ...]} 
     334                /} 
     335        ], 
     336        return => {desc => 'ID of newly created bib record, Event on error'} 
     337    } 
     338); 
     339 
     340sub create_lineitem_assets { 
     341    my($self, $conn, $auth, $li_id, $options) = @_; 
     342    my $e = new_editor(authtoken=>$auth, xact=>1); 
     343    return $e->die_event unless $e->checkauth; 
     344 
     345    my $li = $e->retrieve_acq_lineitem([$li_id,  
     346        {   flesh => 1, 
     347            flesh_fields => {jub => ['purchase_order']} 
     348        } 
     349    ]); 
     350 
     351    return OpenILS::Event->new('BAD_PARAMS') # make this perm-based, not owner-based 
     352        unless $li->purchase_order->owner == $e->requestor->id; 
     353 
     354    my $record = $U->simplereq( 
     355        'open-ils.cat',  
     356        'open-ils.cat.biblio.record.xml.import', 
     357        $auth, $li->marc, $li->source_label); 
     358 
     359    return $record and $e->rollback if $U->event_code($record); 
     360    $logger->info("acq created new lineitem bib record ".$record->id); 
     361 
     362    return $record->id unless $$options{volumes}; 
     363 
     364    for my $vol (@{$$options{volumes}}) { 
     365        my $volume = Fieldmapper::asset::call_number->new; 
     366        $volume->isnew(1); 
     367        $volume->record($record->id); 
     368        $volume->$_($vol->{$_}) for keys %$vol; 
     369        $volume->copies([]); 
     370 
     371        if($vol->{copies}) { 
     372            for my $cp (@{$vol->{copies}}) { 
     373                my $copy = Fieldmapper::asset::copy->new; 
     374                $copy->isnew(1); 
     375                $copy->$_($cp->{$_}) for keys %$cp; 
     376                $copy->loan_duration(2) unless $copy->loan_duration; 
     377                $copy->fine_level(2) unless $copy->fine_level; 
     378                $copy->status(OILS_COPY_STATUS_ON_ORDER) unless $copy->status; 
     379                push(@{$volume->copies}, $copy); 
     380            } 
     381        } 
     382 
     383        my $stat = $U->simplereq( 
     384            'open-ils.cat', 
     385            'open-ils.cat.asset.volume.fleshed.batch.update', $auth, [$volume]); 
     386        return $stat and $e->rollback if $U->event_code($stat); 
     387        $logger->info("acq created new lineitem volume ".$volume->label); 
     388    } 
     389 
     390    $li->eg_bib_id($record->id); 
     391    $e->update_acq_lineitem($li) or return $e->die_event; 
     392    $e->commit; 
     393 
     394    return 1; 
     395} 
     396 
     397 
     398 
     399__PACKAGE__->register_method( 
    323400        method => 'retrieve_lineitem', 
    324401        api_name        => 'open-ils.acq.lineitem.retrieve', 
     
    335412    } 
    336413); 
     414 
    337415 
    338416sub retrieve_lineitem {