details:   https://code.openbravo.com/erp/devel/pi/rev/bfe0fd55340f
changeset: 30381:bfe0fd55340f
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Tue Oct 11 14:42:30 2016 +0200
summary:   Related to issue 34068: Fix stock valuation

Fix stock valuation in case we are updating valuation but stock was not updated 
yet.
Only in case we are updating stock and it is updated to zero, valuation will be 
updated to zero too.

diffstat:

 src-db/database/model/functions/M_UPDATE_STOCK_VALUATION.xml |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (27 lines):

diff -r dc0e10831b4e -r bfe0fd55340f 
src-db/database/model/functions/M_UPDATE_STOCK_VALUATION.xml
--- a/src-db/database/model/functions/M_UPDATE_STOCK_VALUATION.xml      Mon Oct 
10 11:09:34 2016 +0200
+++ b/src-db/database/model/functions/M_UPDATE_STOCK_VALUATION.xml      Tue Oct 
11 14:42:30 2016 +0200
@@ -71,7 +71,7 @@
     JOIN ad_client c ON o.ad_client_id = c.ad_client_id
   WHERE o.ad_org_id = p_org;
 
-  SELECT COUNT(*), COALESCE(SUM(stock), 0), COALESCE(SUM(stock_valuation),0)
+  SELECT COUNT(*), COALESCE(SUM(stock), 0), COALESCE(SUM(stock_valuation), 0)
     INTO v_count, v_stock, v_valuation
   FROM m_stock_valuation
   WHERE ad_client_id = p_client
@@ -84,10 +84,13 @@
 
   IF (v_stock = 0) THEN
     v_unit_price := 0;
-    v_valuation := 0;
+    IF (p_stock <> 0) THEN
+      v_valuation := 0;
+    END IF;
   ELSE
     v_unit_price := ROUND(v_valuation/v_stock, v_costprecission);
   END IF;
+
   IF (v_count > 0) THEN
     UPDATE m_stock_valuation
     SET stock = v_stock,

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to