Issue #23658:ensure itemsite_value is 0 when qtyonhand is 0
authorgaryhgohoos <gary@xtuple.com>
Fri, 6 Jun 2014 15:49:48 +0000 (11:49 -0400)
committergaryhgohoos <gary@xtuple.com>
Fri, 6 Jun 2014 15:49:48 +0000 (11:49 -0400)
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