[open-ils-commits] r12880 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Apr 15 12:07:50 EDT 2009
Author: erickson
Date: 2009-04-15 12:07:47 -0400 (Wed, 15 Apr 2009)
New Revision: 12880
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
Log:
moved po create into order.pm. some other refactoring of asset creation
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm 2009-04-15 15:49:51 UTC (rev 12879)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm 2009-04-15 16:07:47 UTC (rev 12880)
@@ -526,93 +526,7 @@
}
-# ----------------------------------------------------------------------------
-# 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, $po, $args) = @_;
- $args ||= {};
-
- my $e = new_editor(xact=>1, authtoken=>$auth);
- return $e->die_event unless $e->checkauth;
- return $e->die_event unless $e->allowed('CREATE_PURCHASE_ORDER', $po->ordering_agency);
-
- # create the PO
- $po->ordering_agency($e->requestor->ws_ou);
- my $evt = create_purchase_order_impl($e, $po);
- return $evt if $evt;
-
- my $progress = 0;
- my $total_debits = 0;
- my $total_copies = 0;
-
- my $respond = sub {
- $conn->respond({
- @_,
- progress => ++$progress,
- total_debits => $total_debits,
- total_copies => $total_copies,
- });
- };
-
- if($$args{lineitems}) {
-
- for my $li_id (@{$$args{lineitems}}) {
-
- my $li = $e->retrieve_acq_lineitem([
- $li_id,
- {flesh => 1, flesh_fields => {jub => ['attributes']}}
- ]) or return $e->die_event;
-
- # point the lineitems at the new PO
- $li->provider($po->provider);
- $li->purchase_order($po->id);
- $li->editor($e->requestor->id);
- $li->edit_time('now');
- $e->update_acq_lineitem($li) or return $e->die_event;
- $respond->(action => 'update_lineitem');
-
- # create the bibs/volumes/copies in the Evergreen database
- if($$args{create_assets}) {
- # args = {circ_modifier => code}
- my ($count, $evt) = create_lineitem_assets_impl($e, $li_id, $args);
- return $evt if $evt;
- $total_copies+= $count;
- $respond->(action => 'create_assets');
- }
-
- # create the debits
- if($$args{create_debits}) {
- # args = {encumberance => true}
- my ($total, $evt) = create_li_debit_impl($e, $li, $args);
- return $evt if $evt;
- $total_debits += $total;
- $respond->(action => 'create_debit');
- }
- }
- }
-
- $e->commit;
- $respond->(complete => 1, purchase_order => $po->id);
- return undef;
-}
-
-
-__PACKAGE__->register_method(
method => 'create_lineitem_assets',
api_name => 'open-ils.acq.lineitem.assets.create',
signature => {
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2009-04-15 15:49:51 UTC (rev 12879)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm 2009-04-15 16:07:47 UTC (rev 12880)
@@ -125,6 +125,7 @@
sub process_ingest_records {
my $self = shift;
+ return unless @{$self->{ingest_queue}};
for my $req (@{$self->{ingest_queue}}) {
@@ -221,6 +222,22 @@
return $mgr->editor->delete_acq_lineitem($li);
}
+# begins and commit transactions as it goes
+sub create_lineitem_list_assets {
+ my($mgr, $li_ids) = @_;
+ # create the bibs/volumes/copies and ingest the records
+ for my $li_id (@$li_ids) {
+ $mgr->editor->xact_begin;
+ my $data = create_lineitem_assets($mgr, $li_id) or return undef;
+ $mgr->editor->xact_commit;
+ $mgr->push_ingest_queue($data->{li}->eg_bib_id) if $data->{new_bib};
+ $mgr->respond;
+ }
+ $mgr->process_ingest_records;
+ return 1;
+}
+
+
# ----------------------------------------------------------------------------
# Lineitem Detail
# ----------------------------------------------------------------------------
@@ -864,15 +881,7 @@
$cache->delete_cache('vandelay_import_spool_' . $key);
if($create_assets) {
- # create the bibs/volumes/copies and ingest the records
- for my $li_id (@li_list) {
- $e->xact_begin;
- my $data = create_lineitem_assets($mgr, $li_id) or return $e->die_event;
- $e->xact_commit;
- $mgr->push_ingest_queue($data->{li}->eg_bib_id) if $data->{new_bib};
- $mgr->respond;
- }
- $mgr->process_ingest_records;
+ create_lineitem_list_assets($mgr, \@li_list) or return $e->die_event;
}
return $mgr->respond_complete;
@@ -1078,16 +1087,76 @@
$mgr->total(scalar(@$li_ids) + $lid_total);
- for my $li_id (@$li_ids) {
- return $e->die_event unless create_lineitem_assets($mgr, $li_id);
- $mgr->respond;
+ create_lineitem_list_assets($mgr, $li_ids) or return $e->die_event;
+
+ $e->xact_begin;
+ update_purchase_order($mgr, $po) or return $e->die_event;
+ $e->commit;
+
+ return $mgr->respond_complete;
+}
+
+
+
+__PACKAGE__->register_method(
+ method => 'create_purchase_order_api',
+ 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'}
}
+);
- return $e->die_event unless update_purchase_order($mgr, $po);
+sub create_purchase_order_api {
+ my($self, $conn, $auth, $po, $args) = @_;
+ $args ||= {};
- $e->commit;
- $mgr->process_ingest_records;
+ my $e = new_editor(xact=>1, authtoken=>$auth);
+ return $e->die_event unless $e->checkauth;
+ return $e->die_event unless $e->allowed('CREATE_PURCHASE_ORDER', $po->ordering_agency);
+ my $mgr = OpenILS::Application::Acq::BatchManager->new(
+ editor => $e,
+ conn => $conn,
+ throttle => 5
+ );
+
+ # create the PO
+ my %pargs = (ordering_agency => $e->requestor->ws_ou);
+ $pargs{provider} = $po->provider if $po->provider;
+ $po = create_purchase_order($mgr, %pargs) or return $e->die_event;
+
+ my $li_ids = $$args{lineitems};
+
+ if($li_ids) {
+
+ for my $li_id (@$li_ids) {
+
+ my $li = $e->retrieve_acq_lineitem([
+ $li_id,
+ {flesh => 1, flesh_fields => {jub => ['attributes']}}
+ ]) or return $e->die_event;
+
+ $li->provider($po->provider);
+ $li->purchase_order($po->id);
+ update_lineitem($mgr, $li) or return $e->die_event;
+ $mgr->respond;
+
+ create_lineitem_debits($mgr, $li) or return $e->die_event;
+ }
+ }
+
+ # commit before starting the asset creation
+ $e->xact_commit;
+
+ if($li_ids and $$args{create_assets}) {
+ create_lineitem_list_assets($mgr, $li_ids) or return $e->die_event;
+ }
+
return $mgr->respond_complete;
}
More information about the open-ils-commits
mailing list