From 5f7fea643760018c134b367047a120ae91090251 Mon Sep 17 00:00:00 2001 From: senator Date: Tue, 9 Feb 2010 14:49:16 +0000 Subject: [PATCH] Record applications of distribution formulas to lineitems in a new DB table. git-svn-id: svn://svn.open-ils.org/ILS/trunk@15480 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 31 +++++++++++ .../perlmods/OpenILS/Application/Acq/Picklist.pm | 63 ++++++++++++++++++++++ Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/200.schema.acq.sql | 17 ++++++ Open-ILS/web/js/dojo/openils/acq/nls/acq.js | 3 +- Open-ILS/web/js/ui/default/acq/common/li_table.js | 29 +++++++++- 6 files changed, 142 insertions(+), 3 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 8f3a37cd2a..aa4bf9f087 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -5491,6 +5491,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm index d0509c847d..b49daef2fe 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm @@ -365,6 +365,69 @@ request open-ils.cstore open-ils.cstore.json_query.atomic {"select":{"jub":[{"tr __PACKAGE__->register_method( + method => "record_distribution_formula_application", + api_name => "open-ils.acq.distribution_formula.record_application", + signature => { + desc => "Record the application (which actually happens on the " . + "client side) of a distribution formula to a PO or a PL", + params => [ + {desc => "Authentication token", type => "string"}, + {desc => "Formulae applied", "type" => "array"}, + {desc => "Lineitem ID", "type" => "number"} + ], + return => {desc => "acqdfa IDs on success; event on failure"} + } +); + +sub record_distribution_formula_application { + my ($self, $conn, $auth, $formulae, $li_id) = @_; + + my $e = new_editor("authtoken" => $auth, "xact" => 1); + return $e->die_event unless $e->checkauth; + + # We need this to determine relevant OU for testing permissions... + my $li = $e->retrieve_acq_lineitem([ + $li_id, { + "flesh" => 1, + "flesh_fields" => {"jub" => [qw/purchase_order picklist/]} + } + ]) or return $e->die_event; + + # ... which we do here. + my $ou; + if ($li->purchase_order) { + $ou = $li->purchase_order->ordering_agency; + } elsif ($li->picklist) { + $ou = $li->picklist->org_unit; + } else { + $e->rollback; + return new OpenILS::Event("BAD_PARAMS"); + } + + return $e->die_event unless $e->allowed("CREATE_PURCHASE_ORDER", $ou); + + # Just deal with it if $formulate is a scalar instead of an array. + $formulae = [ $formulae ] if not ref $formulae; + + my @results = (); + foreach (@{$formulae}) { + my $acqdfa = new Fieldmapper::acq::distribution_formula_application; + + $acqdfa->creator($e->requestor->id); + $acqdfa->formula($_); + $acqdfa->lineitem($li_id); + + $acqdfa = $e->create_acq_distribution_formula_application($acqdfa) + or return $e->die_event; + push @results, $acqdfa->id; + } + + $e->commit or return $e->die_event; + \@results; +} + + +__PACKAGE__->register_method( method => 'ranged_distrib_formulas', api_name => 'open-ils.acq.distribution_formula.ranged.retrieve', stream => 1, diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index ccbb7e3484..f3cf509f91 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -51,7 +51,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0155'); -- miker +INSERT INTO config.upgrade_log (version) VALUES ('0156'); -- senator CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql index fe0e8bf648..4a2e1a2338 100644 --- a/Open-ILS/src/sql/Pg/200.schema.acq.sql +++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql @@ -543,6 +543,23 @@ CREATE TABLE acq.distribution_formula_entry ( CHECK( owning_lib IS NOT NULL OR location IS NOT NULL ) ); +CREATE TABLE acq.distribution_formula_application ( + id BIGSERIAL PRIMARY KEY, + creator INT NOT NULL REFERENCES actor.usr(id) DEFERRABLE INITIALLY DEFERRED, + create_time TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + formula INT NOT NULL + REFERENCES acq.distribution_formula(id) DEFERRABLE INITIALLY DEFERRED, + lineitem INT NOT NULL + REFERENCES acq.lineitem(id) DEFERRABLE INITIALLY DEFERRED +); + +CREATE INDEX acqdfa_df_idx + ON acq.distribution_formula_application(formula); +CREATE INDEX acqdfa_li_idx + ON acq.distribution_formula_application(lineitem); +CREATE INDEX acqdfa_creator_idx + ON acq.distribution_formula_application(creator); + CREATE TABLE acq.fund_tag ( id SERIAL PRIMARY KEY, owner INT NOT NULL 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 693e961483..dbe003f4f1 100644 --- a/Open-ILS/web/js/dojo/openils/acq/nls/acq.js +++ b/Open-ILS/web/js/dojo/openils/acq/nls/acq.js @@ -5,5 +5,6 @@ '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", - 'CONFIRM_SPLIT_PO': "Are you sure you want to split this purchase order into\none purchase order for every constituent line item?" + 'CONFIRM_SPLIT_PO': "Are you sure you want to split this purchase order into\none purchase order for every constituent line item?", + 'DFA_NOT_ALL': "Could not record all of your applications of distribution forumulae." } diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index 9d97a2e1d8..49c05d8edf 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -34,6 +34,7 @@ function AcqLiTable() { this.liCache = {}; this.plCache = {}; this.poCache = {}; + this.dfaCache = []; this.toggleState = false; this.tbody = dojo.byId('acq-lit-tbody'); this.selectors = []; @@ -545,6 +546,7 @@ function AcqLiTable() { var self = this; this.copyCache = {}; this.copyWidgetCache = {}; + this.dfaCache = []; acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) }; acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() }; @@ -631,6 +633,7 @@ function AcqLiTable() { var copyRows = dojo.query('tr', self.copyTbody); + var acted = false; for(var rowIndex = 0; rowIndex < copyRows.length; rowIndex++) { var row = copyRows[rowIndex]; @@ -658,12 +661,18 @@ function AcqLiTable() { dojo.forEach( ['owning_lib', 'location'], function(field) { - if(entry[field]()) + if(entry[field]()) { + acted = true; copyWidgets[field].attr('value', (entry[field]())); + } } ); } } + + if (acted) { + this.dfaCache.push(formula.id()); + }; }; this._fetchDistribFormulas = function(onload) { @@ -887,6 +896,24 @@ function AcqLiTable() { } } ); + + if (this.dfaCache.length > 0) { + var oldlength = this.dfaCache.length; + fieldmapper.standardRequest( + ["open-ils.acq", + "open-ils.acq.distribution_formula.record_application"], + { + "async": true, + "params": [openils.User.authtoken, this.dfaCache, liId], + "onresponse": function(r) { + var res = openils.Util.readResponse(r); + if (res && res.length != oldlength) + alert(localeStrings.DFA_NOT_ALL); + } + } + ); + this.dfaCache = []; + } } this.applySelectedLiAction = function(action) { -- 2.11.0