[open-ils-commits] r15480 - in trunk/Open-ILS: examples src/perlmods/OpenILS/Application/Acq src/sql/Pg web/js/dojo/openils/acq/nls web/js/ui/default/acq/common (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Feb 9 09:49:18 EST 2010


Author: senator
Date: 2010-02-09 09:49:16 -0500 (Tue, 09 Feb 2010)
New Revision: 15480

Modified:
   trunk/Open-ILS/examples/fm_IDL.xml
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm
   trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
   trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql
   trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
   trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
Log:
Record applications of distribution formulas to lineitems in a new DB table.



Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml	2010-02-09 14:25:22 UTC (rev 15479)
+++ trunk/Open-ILS/examples/fm_IDL.xml	2010-02-09 14:49:16 UTC (rev 15480)
@@ -5491,6 +5491,37 @@
 		</permacrud>
 	</class>
 
+	<class id="acqdfa" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::distribution_formula_application" oils_persist:tablename="acq.distribution_formula_application" reporter:label="Distribution Formula Application">
+		<fields oils_persist:primary="id" oils_persist:sequence="acq.distribution_formula_application_id_seq">
+			<field reporter:label="ID" name="id" reporter:datatype="id"/>
+			<field reporter:label="Creator" name="creator" reporter:datatype="link"/>
+			<field reporter:label="Create Time" name="create_time" reporter:datatype="timestamp"/>
+			<field reporter:label="Distribution Formula" name="formula" reporter:datatype="link"/>
+			<field reporter:label="Lineitem" name="lineitem" reporter:datatype="link"/>
+		</fields>
+		<links>
+			<link field="creator" reltype="has_a" key="id" map="" class="au"/>
+			<link field="formula" reltype="has_a" key="id" map="" class="acqdf"/>
+			<link field="lineitem" reltype="has_a" key="id" map="" class="jub"/>
+		</links>
+		<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+			<actions>
+				<create permission="CREATE_PURCHASE_ORDER">
+					<context link="formula" field="owner"/>
+                </create>
+				<retrieve permission="CREATE_PURCHASE_ORDER">
+					<context link="formula" field="owner"/>
+                </retrieve>
+				<update permission="CREATE_PURCHASE_ORDER">
+					<context link="formula" field="owner"/>
+                </update>
+				<delete permission="CREATE_PURCHASE_ORDER">
+					<context link="formula" field="owner"/>
+                </delete>
+			</actions>
+		</permacrud>
+	</class>
+
 	<class id="acqda" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="acq::debit_attribution" oils_persist:tablename="acq.debit_attribution" reporter:label="Debit Attribution">
 		<fields oils_persist:primary="id">
 			<field reporter:label="Debit Attribution ID" name="id" reporter:datatype="id"/>

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm	2010-02-09 14:25:22 UTC (rev 15479)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm	2010-02-09 14:49:16 UTC (rev 15480)
@@ -365,6 +365,69 @@
 
 
 __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,

Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-02-09 14:25:22 UTC (rev 15479)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql	2010-02-09 14:49:16 UTC (rev 15480)
@@ -51,7 +51,7 @@
     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,

Modified: trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql	2010-02-09 14:25:22 UTC (rev 15479)
+++ trunk/Open-ILS/src/sql/Pg/200.schema.acq.sql	2010-02-09 14:49:16 UTC (rev 15480)
@@ -543,6 +543,23 @@
 				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

Modified: trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2010-02-09 14:25:22 UTC (rev 15479)
+++ trunk/Open-ILS/web/js/dojo/openils/acq/nls/acq.js	2010-02-09 14:49:16 UTC (rev 15480)
@@ -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."
 }

Modified: trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2010-02-09 14:25:22 UTC (rev 15479)
+++ trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2010-02-09 14:49:16 UTC (rev 15480)
@@ -34,6 +34,7 @@
     this.liCache = {};
     this.plCache = {};
     this.poCache = {};
+    this.dfaCache = [];
     this.toggleState = false;
     this.tbody = dojo.byId('acq-lit-tbody');
     this.selectors = [];
@@ -545,6 +546,7 @@
         var self = this;
         this.copyCache = {};
         this.copyWidgetCache = {};
+        this.dfaCache = [];
 
         acqLitSaveCopies.onClick = function() { self.saveCopyChanges(liId) };
         acqLitBatchUpdateCopies.onClick = function() { self.batchCopyUpdate() };
@@ -631,6 +633,7 @@
 
         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 @@
                 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 @@
                 }
             }
         );
+
+        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) {



More information about the open-ils-commits mailing list