Merge pull request #1566 from garyhgohoos/23658
authorGreg Pazo <gpazo@xtuple.com>
Wed, 11 Jun 2014 18:43:35 +0000 (14:43 -0400)
committerGreg Pazo <gpazo@xtuple.com>
Wed, 11 Jun 2014 18:43:35 +0000 (14:43 -0400)
23658:ensure itemsite_value is 0 when qtyonhand is 0

foundation-database/public/functions/postinvtrans.sql

index 6625169..9afe786 100644 (file)
@@ -125,7 +125,11 @@ BEGIN
     _invhistid, itemsite_id, pTransType, _timestamp,
     pQty, itemsite_qtyonhand,
     (itemsite_qtyonhand + (_sense * pQty)),
-    itemsite_costmethod, itemsite_value, itemsite_value + (_r.cost * _sense * pQty),
+    itemsite_costmethod, itemsite_value,
+    -- sanity check to ensure that value = 0 when qtyonhand = 0
+    CASE WHEN ((itemsite_qtyonhand + (_sense * pQty)) + itemsite_nnqoh) = 0.0 THEN 0.0
+         ELSE itemsite_value + (_r.cost * _sense * pQty)
+    END,
     pOrderType, pOrderNumber, pDocNumber, pComments,
     uom_name, _r.cost, _xferwhsid, FALSE, pItemlocSeries
   FROM itemsite, item, uom