Merge pull request #1527 from shackbarth/dbtest
authorLinda Nichols <lynnaloo@gmail.com>
Tue, 3 Jun 2014 16:10:22 +0000 (12:10 -0400)
committerLinda Nichols <lynnaloo@gmail.com>
Tue, 3 Jun 2014 16:10:22 +0000 (12:10 -0400)
POC database test for setmetric

27 files changed:
enyo-client/application/source/models/sales_order_base.js
enyo-client/application/source/views/list.js
enyo-client/database/source/xm/javascript/item_site.sql
enyo-client/extensions/source/crm/client/postbooks.js
enyo-client/extensions/source/project/client/postbooks.js
enyo-client/extensions/source/purchasing/client/postbooks.js
foundation-database/public/functions/calcsalesorderamt.sql
foundation-database/public/functions/convertquote.sql
foundation-database/public/functions/itemcost.sql
foundation-database/public/functions/postcounttaglocation.sql
foundation-database/public/functions/thawitemsite.sql
foundation-database/public/tables/metasql/quoteItems-list.mql
foundation-database/public/tables/metasql/salesOrderItems-list.mql
lib/enyo-x/source/less/dashboard.less
lib/enyo-x/source/stylesheets/screen.css
lib/enyo-x/source/widgets/relation.js
package.json
scripts/lib/build_database.js
scripts/lib/build_database_util.js
scripts/release_build.sh
scripts/xml/distribution_install.xml
scripts/xml/distribution_package.xml
scripts/xml/postbooks_package.xml
scripts/xml/xtmfg_install.xml
scripts/xml/xtmfg_package.xml
test/database/joins.js
test/extensions/sales/sales_order_workspace.js

index 2e441ba..1bd169e 100644 (file)
@@ -1902,7 +1902,9 @@ white:true*/
         }
         parent.calculateScheduleDate();
 
-        this.set("site", parent.get("site") || XT.defaultSite());
+        if (!this.get("site")) {
+          this.set("site", parent.get("site") || XT.defaultSite());
+        }
       }
     },
 
index 161d7f9..90c363a 100644 (file)
@@ -2528,6 +2528,8 @@ trailing:true, white:true, strict: false*/
       ]}
     ]
   });
+  
+  XV.registerModelList("XM.UserAccountRelation", "XV.UserAccountList");
 
   // ..........................................................
   // STATES AND COUNTRIES
index 0014b8d..5ddbacd 100644 (file)
@@ -64,6 +64,7 @@ select xt.install_js('XM','ItemSite','xtuple', $$
       },
       itemJoinMatches,
       itemJoinTable,
+      joinTables = [],
       keySearch = false,
       extra = "",
       qry,
@@ -72,9 +73,9 @@ select xt.install_js('XM','ItemSite','xtuple', $$
       idParams = [],
       etags,
       sqlCount,
-      sql1 = 'select pt1.%3$I as id ' +
+      sql1 = 'select pt1.id ' +
              'from ( ' +
-             'select t1.* as id ' +
+             'select t1.%3$I as id {groupColumns} ' +
              'from %1$I.%2$I t1 {joins} ' +
              'where {conditions} {extra}',
       sql2 = 'select * from %1$I.%2$I where id in ({ids}) {orderBy}';
@@ -89,14 +90,14 @@ select xt.install_js('XM','ItemSite','xtuple', $$
           keySearch = param.value;
           sql1 += ' and t1.%4$I in (select item_id from item where item_number ~^ ${p1} or item_upccode ~^ ${p1}) ' +
             'union ' +
-            'select t1.* ' +
+            'select t1.%3$I as id {groupColumns} ' +
             'from %1$I.%2$I t1 {joins} ' +
             ' join itemalias on t1.%4$I=itemalias_item_id ' +
             '   and itemalias_crmacct_id is null ' +
             'where {conditions} {extra} ' +
             ' and (itemalias_number ~^ ${p1}) ' +
             'union ' +
-            'select t1.* ' +
+            'select t1.%3$I as id {groupColumns}  ' +
             'from %1$I.%2$I t1 {joins} ' +
             ' join itemalias on t1.%4$I=itemalias_item_id ' +
             '   and itemalias_crmacct_id={accountId} ' +
@@ -137,6 +138,9 @@ select xt.install_js('XM','ItemSite','xtuple', $$
       if (itemJoinMatches && itemJoinMatches.length) {
         itemJoinTable = itemJoinMatches[0].match(/(jt\d+)/g);
       }
+
+      /* Get all join table names. */
+      joinTables = clause.joins.match(/(jt\d+)/g).unique();
     }
 
     if (!itemJoinTable) {
@@ -214,7 +218,7 @@ select xt.install_js('XM','ItemSite','xtuple', $$
     }
 
     sql1 = XT.format(
-      sql1 += ') pt1 group by pt1.%3$I{groupBy} {orderBy} %5$s %6$s;',
+      sql1 += ') pt1 group by pt1.id {groupBy} {orderBy} %5$s %6$s;',
       [tableNamespace, table, idColumn, backingTypeJoinColumn, limit, offset]
     );
 
@@ -225,6 +229,9 @@ select xt.install_js('XM','ItemSite','xtuple', $$
       clause.orderByColumns = XT.format('order by t1.%1$I', [idColumn]);
     }
 
+    /* Set columns to include in sub query unions before replacing table alias. */
+    clause.joinGroupColumns = clause.groupByColumns || '';
+
     /* Change table reference in group by and order by to pt1. */
     if (clause.groupByColumns && clause.groupByColumns.length) {
       clause.groupByColumns = clause.groupByColumns.replace(/t1./g, 'pt1.');
@@ -232,12 +239,20 @@ select xt.install_js('XM','ItemSite','xtuple', $$
     if (clause.orderByColumns && clause.orderByColumns.length) {
       clause.orderByColumns = clause.orderByColumns.replace(/t1./g, 'pt1.');
     }
+    if (joinTables.length) {
+      for (var j=0; j < joinTables.length; j++) {
+        var regex = new RegExp(joinTables + '.', 'g');
+        clause.groupByColumns = clause.groupByColumns.replace(regex, 'pt1.');
+        clause.orderByColumns = clause.orderByColumns.replace(regex, 'pt1.');
+      }
+    }
 
     /* Query the model */
     sql1 = sql1.replace(/{conditions}/g, clause.conditions)
              .replace(/{extra}/g, extra)
              .replace(/{joins}/g, clause.joins)
              .replace(/{groupBy}/g, clause.groupByColumns)
+             .replace(/{groupColumns}/g, clause.joinGroupColumns)
              .replace('{orderBy}', clause.orderByColumns)
              .replace('{accountId}', accountId)
              .replace(/{p1}/g, clause.parameters.length + 1)
@@ -257,6 +272,10 @@ select xt.install_js('XM','ItemSite','xtuple', $$
       XT.debug(sql1.slice(1000, 1500));
       XT.debug(sql1.slice(1500, 2000));
       XT.debug(sql1.slice(2000, 2500));
+      XT.debug(sql1.slice(2500, 3000));
+      XT.debug(sql1.slice(3000, 3500));
+      XT.debug(sql1.slice(3500, 4000));
+      XT.debug(sql1.slice(4000, 4500));
       XT.debug('ItemSiteListItem parameters = ', clause.parameters);
     }
     qry = plv8.execute(sql1, clause.parameters);
index 4e317cc..3931981 100644 (file)
@@ -55,7 +55,7 @@ trailing:true, white:true*/
       panels: [
         {name: "accountList", kind: "XV.AccountList"},
         {name: "contactList", kind: "XV.ContactList"},
-        {name: "activityList", kind: "XV.ActivityList"},
+        {name: "crm_activityList", kind: "XV.ActivityList"},
         {name: "toDoList", kind: "XV.ToDoList"},
         {name: "opportunityList", kind: "XV.OpportunityList"},
         {name: "incidentList", kind: "XV.IncidentList", toggleSelected: false}
index cc42498..22cd288 100644 (file)
@@ -41,7 +41,7 @@ trailing:true, white:true, strict:false*/
       label: "_project".loc(),
       panels: [
         {name: "projectList", kind: "XV.ProjectList"},
-        {name: "activityList", kind: "XV.ActivityList"}
+        {name: "project_activityList", kind: "XV.ActivityList"}
       ]
     };
     XT.app.$.postbooks.insertModule(module, 0);
index 21edf9a..3750cb8 100644 (file)
@@ -32,7 +32,7 @@ trailing:true, white:true, strict:false*/
       panels: [
         {name: "ItemSourceList", kind: "XV.ItemSourceList"},
         {name: "purchaseOrderList", kind: "XV.PurchaseOrderList"},
-        {name: "activityList", kind: "XV.ActivityList"}
+        {name: "purchasing_activityList", kind: "XV.ActivityList"}
       ]
     };
     XT.app.$.postbooks.insertModule(module, 0);
index 3c6d188..0f4def9 100644 (file)
@@ -33,7 +33,8 @@ BEGIN
   SELECT COALESCE(SUM(ROUND((coitem_qtyord * coitem_qty_invuomratio) *
                             (coitem_price / coitem_price_invuomratio), 2)), 0.0),
          COALESCE(SUM(ROUND((coitem_qtyord * coitem_qty_invuomratio) *
-                            (coitem_unitcost / coitem_price_invuomratio), 2)), 0.0)
+                            (CASE WHEN (coitem_subnumber > 0) THEN 0.0 ELSE coitem_unitcost END
+                             / coitem_price_invuomratio), 2)), 0.0)
          INTO _subtotal, _cost
   FROM coitem
   WHERE (coitem_cohead_id=pCoheadid)
index 095a778..bf15b9b 100644 (file)
@@ -143,6 +143,7 @@ BEGIN
   FROM quhead JOIN custinfo ON (cust_id=quhead_cust_id)
   WHERE (quhead_id=pQuheadid);
 
+  -- Move Documents
   UPDATE url SET url_source_id = _soheadid,
                  url_source = 'S'
   WHERE ((url_source='Q') AND (url_source_id = pQuheadid));
@@ -155,6 +156,21 @@ BEGIN
                     docass_source_type = 'S'
   WHERE ((docass_source_type='Q') AND (docass_source_id = pQuheadid));
 
+  -- Move Email
+  IF (fetchMetricBool('EnableBatchManager')) THEN
+    UPDATE xtbatch.emlassc SET emlassc_type='S',
+                               emlassc_assc_id=_soheadid
+    WHERE ((emlassc_type='Q') AND (emlassc_assc_id=pQuheadid));
+  END IF;
+
+  -- Copy Characteristics
+  INSERT INTO charass
+        (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default, charass_price)
+  SELECT 'SO', _soheadid, charass_char_id, charass_value, charass_default, charass_price
+    FROM charass
+   WHERE ((charass_target_type='QU')
+     AND  (charass_target_id=pQuheadid));
+
   -- Copy Comments
   INSERT INTO comment
   ( comment_cmnttype_id, comment_source, comment_source_id, comment_date, comment_user, comment_text, comment_public )
@@ -205,6 +221,7 @@ BEGIN
       WHERE (quhead_id=pQuheadid);
     END IF;
 
+    -- Copy Characteristics
     INSERT INTO charass
           (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default, charass_price)
     SELECT 'SI', _soitemid, charass_char_id, charass_value, charass_default, charass_price
index 0d75305..03cef38 100644 (file)
@@ -14,17 +14,28 @@ CREATE OR REPLACE FUNCTION itemCost(pItemid INTEGER,
 -- Overload for future costing enhancements
 --
 DECLARE
+  _r RECORD;
   _cost NUMERIC := 0.0;
 BEGIN
-  IF (fetchMetricBool('WholesalePriceCosting')) THEN
-    SELECT item_listcost INTO _cost
-    FROM item
-    WHERE (item_id=pItemid);
+  -- cache item info
+  SELECT * INTO _r
+  FROM itemsite, item
+  WHERE (itemsite_item_id=pItemid)
+    AND (itemsite_warehous_id=pSiteid)
+    AND (item_id=pItemid);
+
+  IF (_r.item_type = 'K') THEN
+    SELECT SUM(roundQty(itemuomfractionalbyuom(bomitem_item_id, bomitem_uom_id),
+                                               (bomitem_qtyfxd + bomitem_qtyper) * (1 + bomitem_scrap))
+               * stdCost(bomitem_item_id)) INTO _cost
+    FROM bomitem
+    WHERE (bomitem_parent_item_id=_r.item_id)
+      AND (bomitem_rev_id=getActiveRevid('BOM', _r.item_id))
+      AND (pEffective BETWEEN bomitem_effective AND (bomitem_expires - 1));
+  ELSEIF (fetchMetricBool('WholesalePriceCosting')) THEN
+    _cost := _r.item_listcost;
   ELSE
-    SELECT itemcost(itemsite_id) INTO _cost
-    FROM itemsite
-    WHERE (itemsite_item_id=pItemid)
-      AND (itemsite_warehous_id=pSiteid);
+    SELECT itemcost(_r.itemsite_id) INTO _cost;
   END IF;
 
   RETURN _cost;
index 229fe0e..94514b8 100644 (file)
@@ -29,7 +29,7 @@ BEGIN
          itemsite_loccntrl, COALESCE(invcnt_location_id, -1) AS itemsite_location_id,
          CASE WHEN (itemsite_costmethod = 'N') THEN 0
               WHEN ( (itemsite_costmethod = 'A') AND
-                     (itemsite_qtyonhand = 0) AND
+                     ((itemsite_qtyonhand + itemsite_nnqoh) = 0) AND
                      (_avgCostingMethod = 'ACT') ) THEN actcost(itemsite_item_id)
               WHEN ( (itemsite_costmethod = 'A') AND
                      (_avgCostingMethod IN ('ACT', 'AVG')) ) THEN avgcost(itemsite_id)
@@ -241,12 +241,17 @@ BEGIN
     SET itemsite_qtyonhand= itemsite_qtyonhand + (_p.invcnt_qoh_after - _origLocQty),
         itemsite_datelastcount=_postDate
     WHERE (itemsite_id=_p.itemsite_id);
+    UPDATE itemsite
+    SET itemsite_value =  (itemsite_qtyonhand + itemsite_nnqoh) * _p.cost
+    WHERE (itemsite_id=_p.itemsite_id);
   ELSE
     UPDATE itemsite
-    SET itemsite_nnqoh =  itemsite_nnqoh - _origLocQty,
-       itemsite_qtyonhand = itemsite_qtyonhand + _p.invcnt_qoh_after,
+    SET itemsite_nnqoh =  itemsite_nnqoh + (_p.invcnt_qoh_after - _origLocQty),
         itemsite_datelastcount=_postDate
     WHERE (itemsite_id=_p.itemsite_id);
+    UPDATE itemsite
+    SET itemsite_value =  (itemsite_qtyonhand + itemsite_nnqoh) * _p.cost
+    WHERE (itemsite_id=_p.itemsite_id);
   END IF;
  
 --  Post the detail, if any
index ad24fb9..54d85bc 100644 (file)
@@ -167,8 +167,9 @@ BEGIN
     END LOOP;
 
 -- _qoh can be used for the netable qoh because of the negative NN transactions
+-- change to update qtyonhand with _netable_qoh
     UPDATE itemsite
-       SET itemsite_qtyonhand = _qoh,
+       SET itemsite_qtyonhand = _netable_qoh,
            itemsite_nnqoh = _nonnetable_qoh,
            itemsite_value = CASE WHEN ((itemsite_costmethod='A') AND (_value < 0.0)) THEN 0.0
                                  ELSE _value END
index 2c31a83..584fb21 100644 (file)
@@ -22,9 +22,11 @@ SELECT quitem_id,
             ELSE ((1.0 - (quitem_price / quitem_custprice)) * 100.0)
        END AS discountfromcust,
        quitem_unitcost AS coitem_unitcost,
-       ROUND((quitem_qtyord * quitem_qty_invuomratio) *
-             ((quitem_price / quitem_price_invuomratio) - (quitem_unitcost / quitem_price_invuomratio)),2) AS margin,
-       CASE WHEN (quitem_price = 0.0) THEN 100.0
+       CASE WHEN (quitem_price = 0.0) THEN 0.0
+            ELSE ROUND((quitem_qtyord * quitem_qty_invuomratio) *
+                 ((quitem_price / quitem_price_invuomratio) - (quitem_unitcost / quitem_price_invuomratio)),2)
+       END AS margin,
+       CASE WHEN (quitem_price = 0.0) THEN 0.0
             ELSE ((quitem_price - quitem_unitcost) / quitem_price)
        END AS marginpercent,
        CASE WHEN (quitem_custpn != '') THEN quitem_custpn
index d73ca25..3f06697 100644 (file)
@@ -29,6 +29,8 @@ SELECT coitem_id, coitem_altid, groupby,
        coitem_qtyord, qtyshipped, balance, qtyatshipping,
        extprice, extprice_shipped,
        CASE WHEN (discountfromcust=100.0) THEN 'N/A' END AS discountfromcust_qtdisplayrole,
+       CASE WHEN (margin=0.0) THEN 'N/A' END AS margin_qtdisplayrole,
+       CASE WHEN (marginpercent=0.0) THEN 'N/A' END AS marginpercent_qtdisplayrole,
        'qty' AS coitem_qtyord_xtnumericrole,
        'qty' AS qtyshipped_xtnumericrole,
        'qty' AS balance_xtnumericrole,
@@ -98,9 +100,11 @@ SELECT coitem_id,
             ELSE ((1.0 - (coitem_price / coitem_custprice)) * 100.0)
        END AS discountfromcust,
        coitem_unitcost,
-       ROUND((coitem_qtyord * coitem_qty_invuomratio) *
-             ((coitem_price / coitem_price_invuomratio) - (coitem_unitcost / coitem_price_invuomratio)),2) AS margin,
-       CASE WHEN (coitem_price = 0.0) THEN 100.0
+       CASE WHEN (coitem_price = 0.0) THEN 0.0
+            ELSE ROUND((coitem_qtyord * coitem_qty_invuomratio) *
+                 ((coitem_price / coitem_price_invuomratio) - (coitem_unitcost / coitem_price_invuomratio)),2)
+       END AS margin,
+       CASE WHEN (coitem_price = 0.0) THEN 0.0
             ELSE ((coitem_price - coitem_unitcost) / coitem_price)
        END AS marginpercent,
        noNeg(coitem_qtyshipped - coitem_qtyreturned) AS qtyshipped,
index 23b5a07..b33178e 100644 (file)
@@ -11,6 +11,7 @@
 @picker-label: 100px;
 @bottom-border: #444;
 @icon-height: 32px;
+@title-height: 48px;
 
 .dashboard {
   background-color: @gray;
@@ -57,8 +58,9 @@
   }
 
   .chart-title-bar {
-    height: @icon-height;
+    height: @title-height;
     background-color: @lightest-gray;
+    text-transform: none;
     .border-top-radius(10px);
 
     .chart-title {
       color: @black;
       text-align: center;
       /*font-size: 2em;*/
-      font-weight: normal
+      font-weight: normal;
+      font-family: Helvetica;
+    }
+    
+    .chart-sub-title {
+      /*padding-top: 8px;*/
+      color: @blue;
+      text-align: center;
+      font-size: small;
+      font-weight: normal;
+      font-family: Helvetica;
     }
 
     .remove-icon {
       padding: 10px 10px;
     }
   }
+  
+  .chart-filterDrawer {
+    top: 0px;
+  }
+
+  /*  The chart-filters may not be need as we are using the class xv-pullout
+      for styles.  Delete when finished hacking the filter styles.
 
   .chart-filters {
          background-color: @white;
          border-bottom: 1px solid @smoke;
          background: @lightest-gray;
          color: @near-black;
-}
+  }
 
   .chart-filters.xv-parameter-panel .enyo-fittable-columns-layout {
-         padding: 6px 10px;
          border-bottom: 1px solid @smoke;
          background: @white;
     color: @near-black;
-}
+    position: relative;
+    text-align: left;
+    white-space: nowrap;
+  }
+
+  .chart-filters.xv-parameter-panel .enyo-fittable-columns-layout > * {
+    vertical-align: middle;
+  }
+
+  .chart-filters.xv-parameter-panel .xv-label {
+    text-align: right;
+  }
+  
+  */
 
 }
index 600d585..80fc7e7 100755 (executable)
@@ -2649,6 +2649,49 @@ body {
   margin: 10px;
   color: #357ec7;
   overflow: hidden;
+  /*  The chart-filters may not be need as we are using the class xv-pullout
+      for styles.  Delete when finished hacking the filter styles.
+
+  .chart-filters {
+         background-color: @white;
+         
+         -webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);
+         -moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);
+         box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);
+  }
+  
+  .chart-filters .xv-parameter-panel {
+         background-color: @ghost;
+         border: 1px solid @smoke;
+         margin: 0 4px 6px 0;
+         width: 100%;
+  }
+  
+  .chart-filters.xv-parameter-panel .onyx-groupbox-header {
+         padding: 6px 10px;
+         border-bottom: 1px solid @smoke;
+         background: @lightest-gray;
+         color: @near-black;
+  }
+
+  .chart-filters.xv-parameter-panel .enyo-fittable-columns-layout {
+         border-bottom: 1px solid @smoke;
+         background: @white;
+    color: @near-black;
+    position: relative;
+    text-align: left;
+    white-space: nowrap;
+  }
+
+  .chart-filters.xv-parameter-panel .enyo-fittable-columns-layout > * {
+    vertical-align: middle;
+  }
+
+  .chart-filters.xv-parameter-panel .xv-label {
+    text-align: right;
+  }
+  
+  */
 }
 .selectable-chart .xv-list-item {
   border-bottom: 1px solid grey;
@@ -2663,8 +2706,9 @@ body {
   margin-left: 200px;
 }
 .selectable-chart .chart-title-bar {
-  height: 32px;
+  height: 48px;
   background-color: #efefef;
+  text-transform: none;
   -webkit-border-top-right-radius: 10px;
   -moz-border-radius-topright: 10px;
   border-top-right-radius: 10px;
@@ -2678,6 +2722,15 @@ body {
   text-align: center;
   /*font-size: 2em;*/
   font-weight: normal;
+  font-family: Helvetica;
+}
+.selectable-chart .chart-title-bar .chart-sub-title {
+  /*padding-top: 8px;*/
+  color: #0000ff;
+  text-align: center;
+  font-size: small;
+  font-weight: normal;
+  font-family: Helvetica;
 }
 .selectable-chart .chart-title-bar .remove-icon {
   position: absolute;
@@ -2708,29 +2761,8 @@ body {
   width: 130px;
   padding: 10px 10px;
 }
-.selectable-chart .chart-filters {
-  background-color: #fdfdfd;
-  -webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);
-  -moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);
-  box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);
-}
-.selectable-chart .chart-filters .xv-parameter-panel {
-  background-color: #f8f8f8;
-  border: 1px solid #d7d7d7;
-  margin: 0 4px 6px 0;
-  width: 100%;
-}
-.selectable-chart .chart-filters.xv-parameter-panel .onyx-groupbox-header {
-  padding: 6px 10px;
-  border-bottom: 1px solid #d7d7d7;
-  background: #efefef;
-  color: #0e0e0e;
-}
-.selectable-chart .chart-filters.xv-parameter-panel .enyo-fittable-columns-layout {
-  padding: 6px 10px;
-  border-bottom: 1px solid #d7d7d7;
-  background: #fdfdfd;
-  color: #0e0e0e;
+.selectable-chart .chart-filterDrawer {
+  top: 0px;
 }
 /**
   Styles relating to widgets in the pullout
index 81a6027..455bd44 100644 (file)
@@ -117,12 +117,13 @@ regexp:true, undef:true, trailing:true, white:true, strict:false */
         attrs = value ? value.get(key) : "";
         changed = inputValue !== attrs;
       } else {
-        // Must be array. Handle it.
+        // key must be array. Handle it.
         _.each(key, function (str) {
-          var attr = value ? value.get(key) : "";
+          var attr = value ? value.get(str) : "";
           attrs.push(attr);
-          changed = changed || inputValue !== attrs;
         });
+        // if changed or inputValue doesn't match an attr
+        changed = changed || !(_.find(attrs, function (attr) {return inputValue === attr; }));
       }
 
       if (inputValue && changed) {
index aa328dd..b5ecb55 100644 (file)
@@ -62,7 +62,7 @@
   },
   "main": "node-datasource/main.js",
   "scripts": {
-    "build-basic-postbooks-package-sql": "./scripts/explode_manifest.js -m foundation-database/manifest.js -n updates.sql",
+    "build-basic-postbooks-package-sql": "./scripts/explode_manifest.js -m foundation-database/manifest.js -n postbooks_upgrade.sql",
     "build-basic-empty": "./scripts/build_app.js -d empty --databaseonly -e foundation-database -i -s foundation-database/empty_data.sql",
     "build-basic-postbooks-demo": "./scripts/build_app.js -d postbooks_demo --databaseonly -e foundation-database -i -s foundation-database/postbooks_demo_data.sql",
     "build-basic-quickstart": "./scripts/build_app.js -d quickstart --databaseonly -e foundation-database -i -s foundation-database/quickstart_data.sql",
index 784f95b..f7f8934 100644 (file)
@@ -100,7 +100,6 @@ var  async = require('async'),
             isLibOrm ? path.join(extension, "source") :
             path.join(extension, "database/source"),
           manifestOptions = {
-            useSafeFoundationToolkit: isFoundation && !isFoundationExtension && extensions.length === 1,
             useFrozenScripts: spec.frozen,
             useFoundationScripts: baseName.indexOf('inventory') >= 0 ||
               baseName.indexOf('manufacturing') >= 0 ||
index c49404a..e2f85ec 100644 (file)
@@ -14,11 +14,12 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
     dataSource = require('../../node-datasource/lib/ext/datasource').dataSource,
     winston = require('winston');
 
-  var convertFromMetasql = function (content, filename) {
+
+
+
+  var convertFromMetasql = function (content, filename, defaultSchema) {
     var lines = content.split("\n"),
-      schema = filename.indexOf('manufacturing') >= 0 ?
-        "'xtmfg'" :
-        "NULL",
+      schema = defaultSchema ? "'" + defaultSchema + "'" : "NULL",
       group,
       i = 2,
       name,
@@ -53,12 +54,11 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
     return insertSql;
   };
 
-  var convertFromReport = function (content, filename) {
+  var convertFromReport = function (content, filename, defaultSchema) {
     var lines = content.split("\n"),
       name,
-      tableName = filename.indexOf('manufacturing') >= 0 ?
-        "xtmfg.pkgreport" :
-        "report",
+      grade = "0",
+      tableName = defaultSchema ? defaultSchema + ".pkgreport" : "report",
       description,
       disableSql,
       deleteSql,
@@ -72,32 +72,34 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
     name = lines[3].substring(" <name>".length).trim();
     name = name.substring(0, name.indexOf("<"));
     description = lines[4].substring(" <description>".length).trim();
-    description = description.substring(0, name.indexOf("<"));
+    description = description.substring(0, description.indexOf("<"));
+    if (lines[5].indexOf("grade") >= 0) {
+      grade = lines[5].substring(" <grade>".length).trim();
+      grade = grade.substring(0, grade.indexOf("<"));
+    }
 
     disableSql = "ALTER TABLE " + tableName + " DISABLE TRIGGER ALL;";
 
     deleteSql = "delete from " + tableName + " " +
       "where report_name = '" + name +
-      "' and report_grade = 0;";
+      "' and report_grade = " + grade + ";";
 
     insertSql = "insert into " + tableName + " (report_name, report_descrip, " +
       "report_source, report_loaddate, report_grade) VALUES (" +
       "'" + name + "'," +
-      "'" + description + "'," +
+      "$$" + description + "$$," +
       "$$" + content + "$$," +
-      "now(), 0);";
+      "now(), " + grade + ");";
 
     enableSql = "ALTER TABLE " + tableName + " ENABLE TRIGGER ALL;";
 
     return disableSql + deleteSql + insertSql + enableSql;
   };
 
-  var convertFromScript = function (content, filename) {
+  var convertFromScript = function (content, filename, defaultSchema) {
     var name = path.basename(filename, '.js'),
-      tableName = filename.indexOf('manufacturing') >= 0 ?
-        "xtmfg.pkgscript" :
-        "unknown",
-      notes = "xtMfg package",
+      tableName = defaultSchema ? defaultSchema + ".pkgscript" : "unknown",
+      notes = "", //"xtMfg package",
       disableSql,
       deleteSql,
       insertSql,
@@ -120,12 +122,10 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
     return disableSql + deleteSql + insertSql + enableSql;
   };
 
-  var convertFromUiform = function (content, filename) {
+  var convertFromUiform = function (content, filename, defaultSchema) {
     var name = path.basename(filename, '.ui'),
-      tableName = filename.indexOf('manufacturing') >= 0 ?
-        "xtmfg.pkguiform" :
-        "unknown",
-      notes = "xtMfg package",
+      tableName = defaultSchema ? defaultSchema + ".pkguiform" : "unknown",
+      notes = "", //"xtMfg package",
       disableSql,
       deleteSql,
       insertSql,
@@ -174,6 +174,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
       var manifest,
         databaseScripts,
         extraManifestPath,
+        defaultSchema,
         extraManifest,
         extraManifestScripts,
         alterPaths = dbSourceRoot.indexOf("foundation-database") < 0,
@@ -186,6 +187,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
         extensionName = manifest.name;
         extensionComment = manifest.comment;
         databaseScripts = manifest.databaseScripts;
+        defaultSchema = manifest.defaultSchema;
         loadOrder = manifest.loadOrder || 999;
 
       } catch (error) {
@@ -220,8 +222,9 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
       // -e ../private-extensions/source/inventory/foundation-database
 
       if (options.useFoundationScripts) {
-        extraManifest = fs.readFileSync(path.join(dbSourceRoot, "../../foundation-database/manifest.js"));
-        extraManifestScripts = JSON.parse(extraManifest).databaseScripts;
+        extraManifest = JSON.parse(fs.readFileSync(path.join(dbSourceRoot, "../../foundation-database/manifest.js")));
+        defaultSchema = defaultSchema || extraManifest.defaultSchema;
+        extraManifestScripts = extraManifest.databaseScripts;
         extraManifestScripts = _.map(extraManifestScripts, function (path) {
           return "../../foundation-database/" + path;
         });
@@ -234,8 +237,9 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
          path.join(dbSourceRoot, "../../foundation-database/frozen_manifest.js") :
          path.join(dbSourceRoot, "frozen_manifest.js");
 
-        extraManifest = fs.readFileSync(extraManifestPath);
-        extraManifestScripts = JSON.parse(extraManifest).databaseScripts;
+        extraManifest = JSON.parse(fs.readFileSync(extraManifestPath));
+        defaultSchema = defaultSchema || extraManifest.defaultSchema;
+        extraManifestScripts = extraManifest.databaseScripts;
         if (alterPaths) {
           extraManifestScripts = _.map(extraManifestScripts, function (path) {
             return "../../foundation-database/" + path;
@@ -267,7 +271,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
             extname = path.extname(fullFilename).substring(1);
 
           // convert special files: metasql, uiforms, reports, uijs
-          scriptContents = conversionMap[extname](scriptContents, fullFilename);
+          scriptContents = conversionMap[extname](scriptContents, fullFilename, defaultSchema);
           //
           // Allow inclusion of js files in manifest. If it is a js file,
           // use plv8 to execute it.
index 1e8619d..7594812 100755 (executable)
@@ -3,6 +3,7 @@ MAJ=$1
 MIN=$2
 PAT=$3
 
+# Usage: ./scripts/release_build.sh 4 5 0-beta
 echo "BUILDING RELEASE "$MAJ"."$MIN"."$PAT""
 
 git fetch XTUPLE
@@ -25,47 +26,58 @@ npm run-script build-basic-manufacturing-demo
 npm run-script build-basic-distribution-package-sql
 npm run-script build-basic-distribution-empty
 npm run-script build-basic-distribution-quickstart
-#postbooks package
+
+#postbooks upgrade
 cd ../xtuple
-mkdir scripts/output/pb$MAJ$MIN$PAT
-cp scripts/xml/postbooks_package.xml scripts/output/pb$MAJ$MIN$PAT/package.xml
-cp scripts/output/toolkit.sql scripts/output/pb$MAJ$MIN$PAT
-cp scripts/output/updates.sql scripts/output/pb$MAJ$MIN$PAT
+mkdir scripts/output/postbooks-upgrade-$MAJ$MIN$PAT
+cp scripts/xml/postbooks_package.xml scripts/output/postbooks-upgrade-$MAJ$MIN$PAT/package.xml
+cp scripts/output/postbooks_upgrade.sql scripts/output/postbooks-upgrade-$MAJ$MIN$PAT
 cd scripts/output
-tar -zcvf pb$MAJ$MIN$PAT.gz pb$MAJ$MIN$PAT/
-#distribution package
+tar -zcvf postbooks-upgrade-$MAJ$MIN$PAT.gz postbooks-upgrade-$MAJ$MIN$PAT/
+
+#distribution upgrade
 cd ../../
-mkdir scripts/output/dist$MAJ$MIN$PAT
-cp scripts/xml/distribution_package.xml scripts/output/dist$MAJ$MIN$PAT/package.xml
-cp scripts/output/updates.sql scripts/output/dist$MAJ$MIN$PAT
-cp scripts/output/inventory_upgrade.sql scripts/output/dist$MAJ$MIN$PAT
+mkdir scripts/output/distribution-upgrade-$MAJ$MIN$PAT
+cp scripts/xml/distribution_package.xml scripts/output/distribution-upgrade-$MAJ$MIN$PAT/package.xml
+cp scripts/output/postbooks_upgrade.sql scripts/output/distribution-upgrade-$MAJ$MIN$PAT
+cp scripts/output/inventory_upgrade.sql scripts/output/distribution-upgrade-$MAJ$MIN$PAT
+cp scripts/output/distribution_upgrade.sql scripts/output/distribution-upgrade-$MAJ$MIN$PAT
 cd scripts/output
-tar -zcvf dist$MAJ$MIN$PAT.gz dist$MAJ$MIN$PAT/
-#postbooks to distribution
+tar -zcvf distribution-upgrade-$MAJ$MIN$PAT.gz distribution-upgrade-$MAJ$MIN$PAT/
+
+#distribution install
 cd ../../
-mkdir scripts/output/pbtodist$MAJ$MIN$PAT
-cp scripts/xml/distribution_install.xml scripts/output/pbtodist$MAJ$MIN$PAT/package.xml
-cp scripts/output/inventory_basic_install.sql scripts/output/pbtodist$MAJ$MIN$PAT
-cp scripts/output/inventory_upgrade.sql scripts/output/pbtodist$MAJ$MIN$PAT
+mkdir scripts/output/distribution-install-$MAJ$MIN$PAT
+cp scripts/xml/distribution_install.xml scripts/output/distribution-install-$MAJ$MIN$PAT/package.xml
+cp scripts/output/postbooks_upgrade.sql scripts/output/distribution-install-$MAJ$MIN$PAT
+cp scripts/output/inventory_basic_install.sql scripts/output/distribution-install-$MAJ$MIN$PAT
+cp scripts/output/inventory_upgrade.sql scripts/output/distribution-install-$MAJ$MIN$PAT
+cp scripts/output/distribution_basic_install.sql scripts/output/distribution-install-$MAJ$MIN$PAT
+cp scripts/output/distribution_upgrade.sql scripts/output/distribution-install-$MAJ$MIN$PAT
 cd scripts/output
-tar -zcvf pbtodist$MAJ$MIN$PAT.gz pbtodist$MAJ$MIN$PAT/
-#xtmfg packages
+tar -zcvf distribution-install-$MAJ$MIN$PAT.gz distribution-install-$MAJ$MIN$PAT/
+
+#manufacturing upgrade
 cd ../../
-mkdir scripts/output/xtmfg$MAJ$MIN$PAT
-cp scripts/xml/xtmfg_package.xml scripts/output/xtmfg$MAJ$MIN$PAT/package.xml
-cp scripts/output/updates.sql scripts/output/xtmfg$MAJ$MIN$PAT
-cp scripts/output/inventory_upgrade.sql scripts/output/xtmfg$MAJ$MIN$PAT
-cp scripts/output/manufacturing_upgrade.sql scripts/output/xtmfg$MAJ$MIN$PAT
+mkdir scripts/output/manufacturing-upgrade-$MAJ$MIN$PAT
+cp scripts/xml/xtmfg_package.xml scripts/output/manufacturing-upgrade-$MAJ$MIN$PAT/package.xml
+cp scripts/output/postbooks_upgrade.sql scripts/output/manufacturing-upgrade-$MAJ$MIN$PAT
+cp scripts/output/inventory_upgrade.sql scripts/output/manufacturing-upgrade-$MAJ$MIN$PAT
+cp scripts/output/manufacturing_upgrade.sql scripts/output/manufacturing-upgrade-$MAJ$MIN$PAT
 cd scripts/output
-tar -zcvf xtmfg_upgrade-$MAJ$MIN$PAT.gz xtmfg$MAJ$MIN$PAT/
+tar -zcvf manufacturing-upgrade-$MAJ$MIN$PAT.gz manufacturing-upgrade-$MAJ$MIN$PAT/
 
+#manufacturing install
 cd ../../
-mkdir scripts/output/xtmfg_install$MAJ$MIN$PAT
-cp scripts/xml/xtmfg_install.xml scripts/output/xtmfg_install$MAJ$MIN$PAT/package.xml
-cp scripts/output/manufacturing_basic_install.sql scripts/output/xtmfg_install$MAJ$MIN$PAT
-cp scripts/output/manufacturing_upgrade.sql scripts/output/xtmfg_install$MAJ$MIN$PAT
+mkdir scripts/output/manufacturing-install-$MAJ$MIN$PAT
+cp scripts/xml/xtmfg_package.xml scripts/output/manufacturing-install-$MAJ$MIN$PAT/package.xml
+cp scripts/output/postbooks_upgrade.sql scripts/output/manufacturing-install-$MAJ$MIN$PAT
+cp scripts/output/inventory_basic_install.sql scripts/output/manufacturing-install-$MAJ$MIN$PAT
+cp scripts/output/inventory_upgrade.sql scripts/output/manufacturing-install-$MAJ$MIN$PAT
+cp scripts/output/manufacturing_basic_install.sql scripts/output/manufacturing-install-$MAJ$MIN$PAT
+cp scripts/output/manufacturing_upgrade.sql scripts/output/manufacturing-install-$MAJ$MIN$PAT
 cd scripts/output
-tar -zcvf xtmfg_install-$MAJ$MIN$PAT.gz xtmfg_install$MAJ$MIN$PAT/
+tar -zcvf manufacturing-install-$MAJ$MIN$PAT.gz manufacturing-install-$MAJ$MIN$PAT/
 
 ADMIN=admin
 PORT=5432
@@ -78,16 +90,15 @@ done
 
 #cleanup
 cd ../..
-rm -rf scripts/output/pb$MAJ$MIN$PAT/
-rm -rf scripts/output/updates.sql
-rm -rf scripts/output/toolkit.sql
-rm -rf scripts/output/pbtodist$MAJ$MIN$PAT/
-rm -rf scripts/output/dist$MAJ$MIN$PAT/
+rm -rf scripts/output/postbooks-upgrade-$MAJ$MIN$PAT/
+rm -rf scripts/output/postbooks_upgrade.sql
+rm -rf scripts/output/distribution-install-$MAJ$MIN$PAT/
+rm -rf scripts/output/distribution-upgrade-$MAJ$MIN$PAT/
 rm -rf scripts/output/distribution_upgrade.sql
 rm -rf scripts/output/distribution_basic_install.sql
 rm -rf scripts/output/inventory_basic_install.sql
 rm -rf scripts/output/inventory_upgrade.sql
-rm -rf scripts/output/xtmfg$MAJ$MIN$PAT/
-rm -rf scripts/output/xtmfg_install$MAJ$MIN$PAT/
+rm -rf scripts/output/manufacturing-install-$MAJ$MIN$PAT/
+rm -rf scripts/output/manufacturing-upgrade-$MAJ$MIN$PAT/
 rm -rf scripts/output/manufacturing_basic_install.sql
 rm -rf scripts/output/manufacturing_upgrade.sql
index b050f76..6eaa26f 100644 (file)
@@ -1,5 +1,5 @@
-<package id        = "pbtodist450Beta"
-         version   = "4.5.0Beta"
+<package id        = "distribution-install-450"
+         version   = "4.5.0"
          developer = "xTuple"
          descrip   = "load PostBooks resources"
          updater   = "2.2.4" >
 
   <prerequisite type = "query"
                 name = "Checking xTuple ERP database version" >
-    <query>SELECT fetchMetricText('ServerVersion') ~ '^4.4.';</query>
-    <message>This package must be applied to a 4.4+ Postbooks database.
+    <query>SELECT fetchMetricText('ServerVersion') > '4.4.';</query>
+    <message>This package must be applied to a 4.4+ Distribution database.
     </message>
   </prerequisite>
 
+ <prerequisite type = "query"
+                name = "Checking for bad xTuple ERP database version" >
+    <query>SELECT fetchMetricText('ServerVersion') &lt; '4.5.0';</query>
+    <message>This package may not be applied to a 4.5+ Distribution database.
+    </message>
+  </prerequisite>
+
+  <script file="postbooks_upgrade.sql" />
   <script file="inventory_basic_install.sql" />
   <script file="inventory_upgrade.sql" />
+  <script file="distribution_basic_install.sql" />
+  <script file="distribution_upgrade.sql" />
 
 </package>
index 3f2a490..856bca8 100644 (file)
@@ -1,5 +1,5 @@
-<package id        = "dist450Beta"
-         version   = "4.5.0Beta"
+<package id        = "distribution-upgrade-450"
+         version   = "4.5.0"
          developer = "xTuple"
          descrip   = "load PostBooks resources"
          updater   = "2.2.4" >
 
   <prerequisite type = "query"
                 name = "Checking xTuple ERP database version" >
-    <query>SELECT fetchMetricText('ServerVersion') ~ '^4.4.';</query>
+    <query>SELECT fetchMetricText('ServerVersion') > '4.4.';</query>
     <message>This package must be applied to a 4.4+ Distribution database.
     </message>
   </prerequisite>
 
-  <script file="updates.sql" />
+ <prerequisite type = "query"
+                name = "Checking for bad xTuple ERP database version" >
+    <query>SELECT fetchMetricText('ServerVersion') &lt; '4.5.0';</query>
+    <message>This package may not be applied to a 4.5+ Distribution database.
+    </message>
+  </prerequisite>
+
+  <script file="postbooks_upgrade.sql" />
   <script file="inventory_upgrade.sql" />
+  <script file="distribution_upgrade.sql" />
 
 </package>
index db3e6cc..080c8ef 100644 (file)
@@ -1,5 +1,5 @@
-<package id        = "pb450Beta"
-         version   = "4.5.0Beta"
+<package id        = "postbooks-upgrade-450"
+         version   = "4.5.0"
          developer = "xTuple"
          descrip   = "load PostBooks resources"
          updater   = "2.2.4" >
 
   <prerequisite type = "query"
                 name = "Checking xTuple ERP database version" >
-    <query>SELECT fetchMetricText('ServerVersion') ~ '^4.4.';</query>
+    <query>SELECT fetchMetricText('ServerVersion') > '4.4.';</query>
     <message>This package must be applied to a 4.4+ PostBooks database.
     </message>
   </prerequisite>
 
-  <script file="updates.sql" />
+ <prerequisite type = "query"
+                name = "Checking for bad xTuple ERP database version" >
+    <query>SELECT fetchMetricText('ServerVersion') &lt; '4.5.0';</query>
+    <message>This package may not be applied to a 4.5+ Postbooks database.
+    </message>
+  </prerequisite>
+
+  <script file="postbooks_upgrade.sql" />
 
 </package>
index 549c254..6c44928 100644 (file)
@@ -1,5 +1,5 @@
-<package id        = "xtmfg_install450Beta"
-         version   = "4.5.0Beta"
+<package id        = "manufacturing-install-450"
+         version   = "4.5.0"
          developer = "xTuple"
          descrip   = "load PostBooks resources"
          updater   = "2.2.4" >
 
   <prerequisite type = "query"
                 name = "Checking xTuple ERP database version" >
-    <query>SELECT fetchMetricText('ServerVersion') ~ '^4.4.';</query>
-    <message>This package must be applied to a 4.4+ Manufacturing database.
+    <query>SELECT fetchMetricText('ServerVersion') > '4.4.';</query>
+    <message>This package must be applied to a 4.4+ Distribution database.
     </message>
   </prerequisite>
 
+ <prerequisite type = "query"
+                name = "Checking for bad xTuple ERP database version" >
+    <query>SELECT fetchMetricText('ServerVersion')='4.5.0Beta';</query>
+    <message>This package may not be applied to a 4.5.0Beta Distribution database.
+    </message>
+  </prerequisite>
+
+  <script file="postbooks_upgrade.sql" />
+  <script file="inventory_basic_install.sql" />
+  <script file="inventory_upgrade.sql" />
   <script file="manufacturing_basic_install.sql" />
   <script file="manufacturing_upgrade.sql" />
 
index 64940fa..c52d8fb 100644 (file)
@@ -1,5 +1,5 @@
-<package id        = "xtmfg450Beta"
-         version   = "4.5.0Beta"
+<package id        = "manufacturing-upgrade-450"
+         version   = "4.5.0"
          developer = "xTuple"
          descrip   = "load PostBooks resources"
          updater   = "2.2.4" >
 
   <prerequisite type = "query"
                 name = "Checking xTuple ERP database version" >
-    <query>SELECT fetchMetricText('ServerVersion') ~ '^4.4.';</query>
+    <query>SELECT fetchMetricText('ServerVersion') > '4.4.';</query>
     <message>This package must be applied to a 4.4+ Manufacturing database.
     </message>
   </prerequisite>
 
+ <prerequisite type = "query"
+                name = "Checking for bad xTuple ERP database version" >
+    <query>SELECT fetchMetricText('ServerVersion')='4.5.0Beta';</query>
+    <message>This package may not be applied to a 4.5.0Beta Manufacturing database.
+    </message>
+  </prerequisite>
+
+  <script file="postbooks_upgrade.sql" />
+  <script file="inventory_upgrade.sql" />
   <script file="manufacturing_upgrade.sql" />
 
 </package>
index f0b3013..c1fd25a 100644 (file)
@@ -162,6 +162,19 @@ var _ = require("underscore"),
       });
     });
 
+    it('should execute a simple item-site fetch', function (done) {
+      var sql = 'select xt.js_init(true);select xt.post($${"nameSpace":"XM","type":"ItemSiteListItem","dispatch":{"functionName":"fetch","parameters":{"orderBy":[{"attribute":"item.number"}],"parameters":[{"attribute":"isActive","operator":"=","value":true}],"rowOffset":0,"rowLimit":50}},"username":"admin"}$$);';
+
+      datasource.query(sql, creds, function (err, res) {
+        var results;
+        assert.isNull(err);
+        assert.equal(1, res.rowCount, JSON.stringify(res.rows));
+        results = JSON.parse(res.rows[1].post);
+        assert.isNumber(results.length);
+        done();
+      });
+    });
+
     it('should execute an item-site fetch', function (done) {
       var sql = 'select xt.js_init(true);select xt.post($${"nameSpace":"XM","type":"ItemSiteRelation","dispatch":{"functionName":"fetch","parameters":{"parameters":[{"attribute":"item.number","value":"BTRUCK1"},{"attribute":"site.code","value":"WH1"}]}},"username":"admin","encryptionKey":"this is any content"}$$);';
 
@@ -201,6 +214,18 @@ var _ = require("underscore"),
       });
     });
 
+    it('should be able to do a complex item-site search with a keysearch and join table parameters', function (done) {
+      var sql = 'select xt.js_init(true);select xt.post($${"nameSpace":"XM","type":"ItemSiteRelation","dispatch":{"functionName":"fetch","parameters":{"parameters":[{"attribute":"item.isSold","value":true},{"attribute":"item.isActive","value":true},{"attribute":"isSold","value":true},{"attribute":"isActive","value":true},{"attribute":"site.code","value":"WH1"},{"attribute":"customer","value":"TTOYS"},{"attribute":["number","barcode"],"operator":"BEGINS_WITH","value":"btr","keySearch":true}],"orderBy":[{"attribute":"number"},{"attribute":"barcode"}],"rowLimit":10}},"username":"admin"}$$);';
+
+      datasource.query(sql, creds, function (err, res) {
+        var results;
+        assert.isNull(err);
+        assert.equal(1, res.rowCount, JSON.stringify(res.rows));
+        results = JSON.parse(res.rows[1].post);
+        assert.isNumber(results.length);
+        done();
+      });
+    });
 
     it('should support a nested order-by', function (done) {
       var sql = 'select xt.js_init(true);select xt.get($${"nameSpace":"XM","type":"ItemSource","query":{"orderBy":[{"attribute":"vendorItemNumber"},{"attribute":"vendor.name"}],"parameters":[{"attribute":"isActive","value":true},{"attribute":"effective","operator":"<=","value":"2014-03-20T04:00:00.000Z"},{"attribute":"expires","operator":">=","value":"2014-03-22T01:18:09.202Z"}],"rowOffset":0,"rowLimit":50},"username":"admin","encryptionKey":"this is any content"}$$);';
index aacf04f..4964be8 100644 (file)
@@ -13,6 +13,9 @@
     submodels,
     smoke = require("../../lib/smoke"),
     assert = require("chai").assert,
+    gridRow,
+    gridBox,
+    workspace,
     primeSubmodels = function (done) {
       var submodels = {};
       async.series([
     describe('User selects to create a sales order', function () {
       it('User navigates to Sales Order-New and selects to create a new Sales order', function (done) {
         smoke.navigateToNewWorkspace(XT.app, "XV.SalesOrderList", function (workspaceContainer) {
-          var workspace = workspaceContainer.$.workspace,
-            gridRow, gridBox, collect;
+          workspace = workspaceContainer.$.workspace;
 
           assert.equal(workspace.value.recordType, "XM.SalesOrder");
-
           //
           // Set the customer from the appropriate workspace widget
           //
           // know that the workspace is ready to save.
           // It's good practice to set this trigger *before* we change the line
           // item fields, so that we're 100% sure we're ready for the responses.
-          workspace.value.on("change:total", function () {
+          workspace.value.once("change:total", function () {
+            done();
+            /* The following save was moved to the second test
             smoke.saveWorkspace(workspace, function (err, model) {
               assert.isNull(err);
               // TODO: sloppy
               setTimeout(function () {
                 smoke.deleteFromList(XT.app, model, done);
               }, 2000);
-            });
+            });*/
           });
 
           //
           assert.equal(gridBox.liveModels().length, 1);
         });
       });
+      it('adding a second line item should not copy the item', function (done) {
+        workspace.value.once("change:total", function () {
+          smoke.saveWorkspace(workspace, function (err, model) {
+            assert.isNull(err);
+            // TODO: sloppy
+            setTimeout(function () {
+              smoke.deleteFromList(XT.app, model, done);
+            }, 4000);
+          }, true);
+        });
+
+        gridRow.$.itemSiteWidget.$.privateItemSiteWidget.$.input.focus();
+        // Add a new item, check that row exists, and make sure the itemSiteWidget doesn't copy irrelevantly
+        gridBox.newItem();
+        assert.equal(gridBox.liveModels().length, 2);
+        assert.notEqual(submodels.itemModel.id, gridRow.$.itemSiteWidget.$.privateItemSiteWidget.$.input.value);
+
+        // The intention was to delete the above line after verifying that the item doesn't copy but ran into 
+        // many issues so just populating with same data and saving it with 2 line items.
+        gridRow.$.itemSiteWidget.doValueChange({value: {item: submodels.itemModel, site: submodels.siteModel}});
+        gridRow.$.quantityWidget.doValueChange({value: 5});
+        /* Delete the line item
+        workspace.value.get("lineItems").models[1].destroy({
+              success: function () {
+                console.log("success");
+                gridBox.setEditableIndex(null);
+                gridBox.$.editableGridRow.hide();
+                gridBox.valueChanged();
+              }
+            });
+        */
+      });
     });
   });
 }());