Fixes Issue 26143: Division by zero error calculating manufacturing transactions cost
authorPandeeswari Ramakrishnan <pandeeswari.ramakrishnan@openbravo.com>
Wed, 09 Apr 2014 17:01:17 +0530
changeset 22891 c0638f312efc
parent 22890 8552c3633a70
child 22892 075221192871
Fixes Issue 26143: Division by zero error calculating manufacturing transactions cost
src-db/database/model/functions/MA_PRODUCTION_COST.xml
--- a/src-db/database/model/functions/MA_PRODUCTION_COST.xml	Wed Apr 09 08:27:03 2014 +0200
+++ b/src-db/database/model/functions/MA_PRODUCTION_COST.xml	Wed Apr 09 17:01:17 2014 +0530
@@ -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) 2001-2013 Openbravo SLU
+ * All portions are Copyright (C) 2001-2014 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************/
@@ -373,11 +373,15 @@
           --Calculate costs for each produced product.
 
           --Calculate the proportional factor of the cost
-          SELECT COALESCE(SUM(ComponentCost),1)/v_CompCostSum INTO v_CompCost
-          FROM MA_WRPHASEPRODUCT
-          WHERE MA_WRPhase_ID = Cur_ProductionPlan.MA_WRPHASE_ID
-            AND M_Product_ID = Cur_ProductionLine.M_PRODUCT_ID
-            AND PRODUCTIONTYPE = '+';
+          IF (v_CompCostSum = 0) THEN
+            v_CompCost := 0;
+          ELSE
+            SELECT COALESCE(SUM(ComponentCost),1)/v_CompCostSum INTO v_CompCost
+            FROM MA_WRPHASEPRODUCT
+            WHERE MA_WRPhase_ID = Cur_ProductionPlan.MA_WRPHASE_ID
+              AND M_Product_ID = Cur_ProductionLine.M_PRODUCT_ID
+              AND PRODUCTIONTYPE = '+';
+          END IF;
           --Calculate the proportional cost of the production
           v_ResultStr := 'Update component cost';
           UPDATE M_PRODUCTIONLINE