Record applications of distribution formulas to lineitems in a new DB table.
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 9 Feb 2010 14:49:16 +0000 (14:49 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 9 Feb 2010 14:49:16 +0000 (14:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15480 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Acq/Picklist.pm
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/200.schema.acq.sql
Open-ILS/web/js/dojo/openils/acq/nls/acq.js
Open-ILS/web/js/ui/default/acq/common/li_table.js

index 8f3a37c..aa4bf9f 100644 (file)
@@ -5491,6 +5491,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                </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"/>
index d0509c8..b49daef 100644 (file)
@@ -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,
index ccbb7e3..f3cf509 100644 (file)
@@ -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,
index fe0e8bf..4a2e1a2 100644 (file)
@@ -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
index 693e961..dbe003f 100644 (file)
@@ -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."
 }
index 9d97a2e..49c05d8 100644 (file)
@@ -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) {