From 1500d8b8c482a31f0856c604eff73d62180e914f Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 15 Apr 2009 19:32:27 +0000 Subject: [PATCH] moved li_detail CUD into order. removed old lid code git-svn-id: svn://svn.open-ils.org/ILS/trunk@12883 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Acq/Lineitem.pm | 116 --------------------- .../src/perlmods/OpenILS/Application/Acq/Order.pm | 58 +++++++++++ 2 files changed, 58 insertions(+), 116 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm index 1c806338e3..88c716047a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Lineitem.pm @@ -354,30 +354,6 @@ sub lineitem_search_ident { } -__PACKAGE__->register_method( - method => 'create_lineitem_detail', - api_name => 'open-ils.acq.lineitem_detail.create', - signature => { - desc => q/Creates a new purchase order line item detail. - Additionally creates the associated fund_debit/, - params => [ - {desc => 'Authentication token', type => 'string'}, - {desc => 'lineitem_detail to create', type => 'object'}, - ], - return => {desc => 'The purchase order line item detail id, Event on failure'} - } -); - -sub create_lineitem_detail { - my($self, $conn, $auth, $li_detail, $options) = @_; - my $e = new_editor(xact=>1, authtoken=>$auth); - return $e->die_event unless $e->checkauth; - my $res = create_lineitem_detail_impl($self, $conn, $e, $li_detail, $options); - return $e->event if $e->died; - $e->commit; - return $res; -} - __PACKAGE__->register_method( method => 'lineitem_detail_CUD_batch', @@ -463,50 +439,6 @@ sub create_lineitem_detail_impl { } - -__PACKAGE__->register_method( - method => 'update_lineitem_detail', - api_name => 'open-ils.acq.lineitem_detail.update', - signature => { - desc => q/Updates a lineitem detail/, - params => [ - {desc => 'Authentication token', type => 'string'}, - {desc => 'lineitem_detail to update', type => 'object'}, - ], - return => {desc => '1 on success, Event on failure'} - } -); - -sub update_lineitem_detail { - my($self, $conn, $auth, $li_detail) = @_; - my $e = new_editor(xact=>1, authtoken=>$auth); - return $e->die_event unless $e->checkauth; - my $res = update_lineitem_detail_impl($self, $conn, $e, $li_detail); - return $e->event if $e->died; - $e->commit; - return $res; -} - -sub update_lineitem_detail_impl { - my($self, $conn, $e, $li_detail) = @_; - - if($li_detail->fund) { - my $fund = $e->retrieve_acq_fund($li_detail->fund) or return $e->die_event; - return $e->die_event unless - $e->allowed('MANAGE_FUND', $fund->org, $fund); - } - - # XXX check lineitem perms - - my $li = $e->retrieve_acq_lineitem($li_detail->lineitem) - or return $e->die_event; - my $evt = update_li_edit_time($e, $li); - return $evt if $evt; - - $e->update_acq_lineitem_detail($li_detail) or return $e->die_event; - return 1; -} - sub update_li_edit_time { my ($e, $li) = @_; # some lineitem edits are allowed after approval time... @@ -520,54 +452,6 @@ sub update_li_edit_time { __PACKAGE__->register_method( - method => 'delete_lineitem_detail', - api_name => 'open-ils.acq.lineitem_detail.delete', - signature => { - desc => q/Deletes a lineitem detail/, - params => [ - {desc => 'Authentication token', type => 'string'}, - {desc => 'lineitem_detail ID to delete', type => 'number'}, - ], - return => {desc => '1 on success, Event on failure'} - } -); - -sub delete_lineitem_detail { - my($self, $conn, $auth, $li_detail_id) = @_; - my $e = new_editor(xact=>1, authtoken=>$auth); - return $e->die_event unless $e->checkauth; - my $res = delete_lineitem_detail_impl($self, $conn, $e, $li_detail_id); - return $e->event if $e->died; - $e->commit; - return $res; -} - -sub delete_lineitem_detail_impl { - my($self, $conn, $e, $li_detail_id) = @_; - - my $li_detail = $e->retrieve_acq_lineitem_detail([ - $li_detail_id, - { flesh => 1, - flesh_fields => {acqlid => ['lineitem']} - } - ]) or return $e->die_event; - - my $li = $li_detail->lineitem; - - my $evt = update_li_edit_time($e, $li); - return $evt if $evt; - - return OpenILS::Event->new('BAD_PARAMS') unless - $li->state =~ /new|approved/; - - # XXX check lineitem perms - - $e->delete_acq_lineitem_detail($li_detail) or return $e->die_event; - return 1; -} - - -__PACKAGE__->register_method( method => 'retrieve_lineitem_detail', api_name => 'open-ils.acq.lineitem_detail.retrieve', signature => { diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm index ed7524833b..6fea1a4f99 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm @@ -53,6 +53,7 @@ sub respond_complete { sub total { my($self, $val) = @_; $self->{args}->{total} = $val if defined $val; + $self->{args}->{maximum} = $self->{args}->{total}; return $self->{args}->{total}; } sub purchase_order { @@ -1161,4 +1162,61 @@ sub create_purchase_order_api { } +__PACKAGE__->register_method( + method => 'lineitem_detail_CUD_batch', + api_name => 'open-ils.acq.lineitem_detail.cud.batch', + stream => 1, + signature => { + desc => q/Creates a new purchase order line item detail. + Additionally creates the associated fund_debit/, + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'List of lineitem_details to create', type => 'array'}, + ], + return => {desc => 'Streaming response of current position in the array'} + } +); + +sub lineitem_detail_CUD_batch { + my($self, $conn, $auth, $li_details) = @_; + + my $e = new_editor(xact=>1, authtoken=>$auth); + return $e->die_event unless $e->checkauth; + + my $mgr = OpenILS::Application::Acq::BatchManager->new( + editor => $e, + conn => $conn, + throttle => 5 + ); + + # XXX perms + + $mgr->total(scalar(@$li_details)); + + my %li_cache; + + for my $lid (@$li_details) { + + my $li = $li_cache{$lid->lineitem} || $e->retrieve_acq_lineitem($lid->lineitem); + + if($lid->isnew) { + create_lineitem_detail($mgr, %{$lid->to_bare_hash}) or return $e->die_event; + + } elsif($lid->ischanged) { + $e->update_acq_lineitem_detail($lid) or return $e->die_event; + + } elsif($lid->isdeleted) { + delete_lineitem_detail($mgr, $lid) or return $e->die_event; + } + + $mgr->respond(li => $li); + $li_cache{$lid->lineitem} = $li; + } + + $e->commit; + return $mgr->respond_complete; +} + + + 1; -- 2.11.0