details:   https://code.openbravo.com/erp/devel/pi/rev/9a17396e89b4
changeset: 30488:9a17396e89b4
user:      Mark <markmm82 <at> gmail.com>
date:      Tue Oct 11 15:10:05 2016 -0400
summary:   Fixes issue 34055: Fixed errors in Costing Background due to 
rounding issues.

When cost adjustments are created, they should not be taken into account when 
Stock Valuation is initialized because it duplicates the stock amount (caused 
by natural union between tables) inside M_INITIALIZE_STOCK_VALUATION function.

details:   https://code.openbravo.com/erp/devel/pi/rev/839a52f407fc
changeset: 30489:839a52f407fc
user:      Alvaro Ferraz <alvaro.ferraz <at> openbravo.com>
date:      Mon Oct 17 17:00:58 2016 +0200
summary:   Related to issue 34055: Code review improvements

Set zero valuation in case stock is zero and it does not exist any record in 
m_stock_valuation.
Do not sum transaction movementqty, to avoid duplicate stock in case we have 
more than one m_transaction_cost record related to the same transaction.

diffstat:

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

diffs (40 lines):

diff -r f111e305e4c3 -r 839a52f407fc 
src-db/database/model/functions/M_INITIALIZE_STOCK_VALUATION.xml
--- a/src-db/database/model/functions/M_INITIALIZE_STOCK_VALUATION.xml  Mon Oct 
17 18:52:02 2016 +0530
+++ b/src-db/database/model/functions/M_INITIALIZE_STOCK_VALUATION.xml  Mon Oct 
17 17:00:58 2016 +0200
@@ -22,7 +22,7 @@
 * under the License.
 * The Original Code is Openbravo ERP.
 * The Initial Developer of the Original Code is Openbravo SLU
-* All portions are Copyright (C) 2014 Openbravo SLU
+* All portions are Copyright (C) 2014-2016 Openbravo SLU
 * All Rights Reserved.
 * Contributor(s):  ______________________________________.
 ************************************************************************/
@@ -68,13 +68,14 @@
           SELECT SUM(a.qty) as stock, ROUND(SUM(sumcost), v_costprecission) as 
valuation, aux_warehouse_id as m_warehouse_id
           FROM (
             SELECT trx.m_product_id, w.m_warehouse_id AS aux_warehouse_id,
-                SUM(trx.movementqty) AS qty, c_currency_convert_precision(SUM 
(CASE WHEN trx.movementqty < 0 THEN -tc.cost ELSE tc.cost END), 
tc.c_currency_id, v_currency_id, tc.dateacct, NULL, p_client, 
Cur_legal_entities.ad_org_id, 'C') AS sumcost
+                trx.movementqty AS qty, c_currency_convert_precision(SUM (CASE 
WHEN trx.movementqty < 0 THEN -tc.cost ELSE tc.cost END), tc.c_currency_id, 
v_currency_id, tc.dateacct, NULL, p_client, Cur_legal_entities.ad_org_id, 'C') 
AS sumcost
             FROM m_transaction trx
               JOIN m_locator l ON (trx.m_locator_id=l.m_locator_id)
               LEFT JOIN m_warehouse w ON w.m_warehouse_id = CASE 
Cur_legal_entities.warehouse_dimension WHEN 'Y' THEN l.m_warehouse_id ELSE '-1' 
END
               LEFT JOIN m_transaction_cost tc ON (trx.m_transaction_id = 
tc.m_transaction_id)
             WHERE trx.m_product_id = cur_products.m_product_id
               AND trx.iscostcalculated = 'Y'
+              AND tc.isunitcost = 'Y'
               AND AD_ORG_ISINNATURALTREE(trx.ad_org_id, 
Cur_legal_entities.ad_org_id, p_client) ='Y'
               AND trx.ad_client_id = p_client
             GROUP BY trx.m_transaction_id, trx.m_product_id, tc.c_currency_id, 
tc.dateacct, w.m_warehouse_id, trx.movementqty
diff -r f111e305e4c3 -r 839a52f407fc 
src-db/database/model/functions/M_UPDATE_STOCK_VALUATION.xml
--- a/src-db/database/model/functions/M_UPDATE_STOCK_VALUATION.xml      Mon Oct 
17 18:52:02 2016 +0530
+++ b/src-db/database/model/functions/M_UPDATE_STOCK_VALUATION.xml      Mon Oct 
17 17:00:58 2016 +0200
@@ -84,7 +84,7 @@
 
   IF (v_stock = 0) THEN
     v_unit_price := 0;
-    IF (p_stock <> 0) THEN
+    IF (p_stock <> 0 OR v_count = 0) THEN
       v_valuation := 0;
     END IF;
   ELSE

------------------------------------------------------------------------------
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