From 9ef52bbfaa6d034e990ee68867ab0a0c13adb51c Mon Sep 17 00:00:00 2001 From: senator Date: Fri, 5 Feb 2010 21:55:23 +0000 Subject: [PATCH] Acq: Give users a way to split one PO into many (one PO per lineitem). After splitting, the staff client user is directed to the PO search interface and is shown a combined view of all the newly separated POs. git-svn-id: svn://svn.open-ils.org/ILS/trunk@15467 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 2 + Open-ILS/src/extras/ils_events.xml | 6 ++ .../src/perlmods/OpenILS/Application/Acq/Order.pm | 88 +++++++++++++++++++++- Open-ILS/web/js/dojo/openils/acq/nls/acq.js | 3 +- Open-ILS/web/js/ui/default/acq/po/search.js | 12 ++- Open-ILS/web/js/ui/default/acq/po/view_po.js | 32 +++++++- Open-ILS/web/templates/default/acq/po/search.tt2 | 6 ++ Open-ILS/web/templates/default/acq/po/view.tt2 | 1 + 8 files changed, 145 insertions(+), 5 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index e21c101b73..bdafe1099a 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -4824,6 +4824,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + @@ -4835,6 +4836,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/src/extras/ils_events.xml b/Open-ILS/src/extras/ils_events.xml index b9897700aa..fde2d9e7f2 100644 --- a/Open-ILS/src/extras/ils_events.xml +++ b/Open-ILS/src/extras/ils_events.xml @@ -645,6 +645,12 @@ The requested acq.purchase_order was not found + + The requested acq.purchase_order cannot be split because it does not have more than one lineitem + + + The requested acq.purchase_order cannot be split because it has gone beyond the "pending" state + The requested acq.lineitem_detail was not found diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm index 77a2136d94..c8d0986bf1 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Order.pm @@ -1291,8 +1291,9 @@ sub create_purchase_order_api { my $mgr = OpenILS::Application::Acq::BatchManager->new(editor => $e, conn => $conn); # create the PO - my %pargs = (ordering_agency => $e->requestor->ws_ou); + my %pargs = (ordering_agency => $e->requestor->ws_ou); # default $pargs{provider} = $po->provider if $po->provider; + $pargs{ordering_agency} = $po->ordering_agency if $po->ordering_agency; $po = create_purchase_order($mgr, %pargs) or return $e->die_event; my $li_ids = $$args{lineitems}; @@ -1827,4 +1828,89 @@ sub activate_purchase_order { } +__PACKAGE__->register_method( + method => 'split_purchase_order_by_lineitems', + api_name => 'open-ils.acq.purchase_order.split_by_lineitems', + signature => { + desc => q/Splits a PO into many POs, 1 per lineitem. Only works for + POs a) with more than one lineitems, and b) in the "pending" state./, + params => [ + {desc => 'Authentication token', type => 'string'}, + {desc => 'Purchase order ID', type => 'number'} + ], + return => {desc => 'list of new PO IDs on success, Event on error'} + } +); + +sub split_purchase_order_by_lineitems { + my ($self, $conn, $auth, $po_id) = @_; + + my $e = new_editor("xact" => 1, "authtoken" => $auth); + return $e->die_event unless $e->checkauth; + + my $po = $e->retrieve_acq_purchase_order([ + $po_id, { + "flesh" => 1, + "flesh_fields" => {"acqpo" => [qw/lineitems notes/]} + } + ]) or return $e->die_event; + + return $e->die_event + unless $e->allowed("CREATE_PURCHASE_ORDER", $po->ordering_agency); + + unless ($po->state eq "pending") { + $e->rollback; + return new OpenILS::Event("ACQ_PURCHASE_ORDER_TOO_LATE"); + } + + unless (@{$po->lineitems} > 1) { + $e->rollback; + return new OpenILS::Event("ACQ_PURCHASE_ORDER_TOO_SHORT"); + } + + # To split an existing PO into many, it seems unwise to just delete the + # original PO, so we'll instead detach all of the original POs' lineitems + # but the first, then create new POs for each of the remaining LIs, and + # then attach the LIs to their new POs. + + my @po_ids = ($po->id); + my @moving_li = @{$po->lineitems}; + shift @moving_li; # discard first LI + + foreach my $li (@moving_li) { + my $new_po = $po->clone; + $new_po->clear_id; + $new_po->clear_name; + $new_po->creator($e->requestor->id); + $new_po->editor($e->requestor->id); + $new_po->owner($e->requestor->id); + $new_po->edit_time("now"); + $new_po->create_time("now"); + + $new_po = $e->create_acq_purchase_order($new_po); + + # Clone any notes attached to the old PO and attach to the new one. + foreach my $note (@{$po->notes}) { + my $new_note = $note->clone; + $new_note->clear_id; + $new_note->edit_time("now"); + $new_note->purchase_order($new_po->id); + $e->create_acq_po_note($new_note); + } + + $li->edit_time("now"); + $li->purchase_order($new_po->id); + $e->update_acq_lineitem($li); + + push @po_ids, $new_po->id; + } + + $po->edit_time("now"); + $e->update_acq_purchase_order($po); + + return \@po_ids if $e->commit; + return $e->die_event; +} + + 1; diff --git a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js index d6a9d517e4..693e961483 100644 --- a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js +++ b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js @@ -4,5 +4,6 @@ 'XUL_RECORD_DETAIL_PAGE' : 'Record Details', 'DELETE_LI_COPIES_CONFIRM' : 'This will delete the last ${0} copies in the table. Proceed?', 'NO_PO_RESULTS': "No results", - 'PO_HEADING_ERROR' : "Unexpected problem building virtual combined PO" + 'PO_HEADING_ERROR' : "Unexpected problem building virtual combined PO", + 'CONFIRM_SPLIT_PO': "Are you sure you want to split this purchase order into\none purchase order for every constituent line item?" } diff --git a/Open-ILS/web/js/ui/default/acq/po/search.js b/Open-ILS/web/js/ui/default/acq/po/search.js index 30aa6ebc39..b4185aee14 100644 --- a/Open-ILS/web/js/ui/default/acq/po/search.js +++ b/Open-ILS/web/js/ui/default/acq/po/search.js @@ -32,7 +32,10 @@ function doSearch(fields) { delete fields.metapo_view; } - if(isNaN(fields.id)) { + if ( + !(fields.id && fields.id.constructor.name == 'Array') && + isNaN(fields.id) + ) { delete fields.id; for(var k in fields) { if(fields[k] == '' || fields[k] == null) @@ -48,6 +51,7 @@ function doSearch(fields) { for(var k in fields) some = true; if(!some) fields.id = {'!=' : null}; + if (metapo_view) { openils.Util.hide("holds_po_grid"); loadMetaPO(fields); @@ -77,7 +81,11 @@ function loadForm() { dijitArgs : {name:'ordering_agency', required:false} }).build(); - doSearch({ordering_agency : openils.User.user.ws_ou()}); + if (poIds && poIds.length > 0) { + doSearch({"id": poIds, "metapo_view": [true] /* [sic] */}); + } else { + doSearch({"ordering_agency": openils.User.user.ws_ou()}); + } } function loadMetaPO(fields) { diff --git a/Open-ILS/web/js/ui/default/acq/po/view_po.js b/Open-ILS/web/js/ui/default/acq/po/view_po.js index 742d4efb6d..76294bc7b5 100644 --- a/Open-ILS/web/js/ui/default/acq/po/view_po.js +++ b/Open-ILS/web/js/ui/default/acq/po/view_po.js @@ -24,8 +24,12 @@ function init() { dojo.byId('acq-po-view-total-spent').innerHTML = PO.amount_spent(); dojo.byId('acq-po-view-state').innerHTML = PO.state(); // TODO i18n - if(PO.state() == 'pending') + if(PO.state() == 'pending') { openils.Util.show('acq-po-activate'); + if (PO.lineitem_count() > 1) { + openils.Util.show('acq-po-split'); + } + } } } ); @@ -59,6 +63,32 @@ function activatePo() { } } +function splitPo() { + progressDialog.show(true); + try { + var list; + fieldmapper.standardRequest( + ['open-ils.acq', 'open-ils.acq.purchase_order.split_by_lineitems'], + { async: true, + params: [openils.User.authtoken, PO.id()], + onresponse : function(r) { + list = openils.Util.readResponse(r); + }, + oncomplete : function() { + progressDialog.hide(); + if (list) { + location.href = oilsBasePath + '/eg/acq/po/search/' + + list.join(","); + } + } + } + ); + } catch(E) { + progressDialog.hide(); + alert(E); + } +} + function updatePoName() { var value = prompt('Enter new purchase order name:', PO.name()); // TODO i18n if(!value || value == PO.name()) return; diff --git a/Open-ILS/web/templates/default/acq/po/search.tt2 b/Open-ILS/web/templates/default/acq/po/search.tt2 index d152efbd0e..07dcfcb4c5 100644 --- a/Open-ILS/web/templates/default/acq/po/search.tt2 +++ b/Open-ILS/web/templates/default/acq/po/search.tt2 @@ -1,5 +1,11 @@ [% WRAPPER default/base.tt2 %] [% ctx.page_title = 'Purchase Orders' %] +
PO Search
diff --git a/Open-ILS/web/templates/default/acq/po/view.tt2 b/Open-ILS/web/templates/default/acq/po/view.tt2 index 4b7073a66a..7b04973bf0 100644 --- a/Open-ILS/web/templates/default/acq/po/view.tt2 +++ b/Open-ILS/web/templates/default/acq/po/view.tt2 @@ -14,6 +14,7 @@ Total Spent$ Status + -- 2.11.0