Issue #23507:correctly handle non-netable
authorgaryhgohoos <gary@xtuple.com>
Thu, 29 May 2014 17:36:40 +0000 (13:36 -0400)
committergaryhgohoos <gary@xtuple.com>
Thu, 29 May 2014 17:36:40 +0000 (13:36 -0400)
foundation-database/public/functions/postcounttaglocation.sql
foundation-database/public/functions/thawitemsite.sql

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