Fixes issue 0013959: Error division by zero when processing Purchasing Plan
authorAdrián Romero <adrianromero@openbravo.com>
Thu, 22 Jul 2010 18:22:49 +0200
changeset 7907 d24e1139ded8
parent 7906 5013a579164c
child 7908 a24b3384f853
Fixes issue 0013959: Error division by zero when processing Purchasing Plan
It has been added a check that verifies when the capacity is zero and raises an error message explaining it
src-db/database/model/functions/MRP_PURCHASEPLAN.xml
src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/model/functions/MRP_PURCHASEPLAN.xml	Thu Jul 22 10:02:25 2010 +0530
+++ b/src-db/database/model/functions/MRP_PURCHASEPLAN.xml	Thu Jul 22 18:22:49 2010 +0200
@@ -72,7 +72,7 @@
     v_ResultStr := 'Purchase mrp';
 
     FOR Cur_PlanProduct IN (
-        SELECT MRP_RUN_PURCHASELINE.M_PRODUCT_ID,
+        SELECT MRP_RUN_PURCHASELINE.M_PRODUCT_ID, M_PRODUCT.NAME AS PRODUCTNAME,
           COALESCE(M_PRODUCT_PO.CAPACITY, M_PRODUCT_ORG.CAPACITY, M_PRODUCT.CAPACITY) AS CAPACITY,
           COALESCE(M_PRODUCT_PO.DELIVERYTIME_PROMISED, M_PRODUCT_ORG.DELAYMIN, M_PRODUCT.DELAYMIN, 0) AS DELAYMIN,
           COALESCE(M_PRODUCT_PO.QTYTYPE, M_PRODUCT_ORG.QTYTYPE, M_PRODUCT_ORG.QTYTYPE, 'E') AS qtytype,
@@ -93,7 +93,7 @@
           AND PRODUCT_PO.C_BPARTNER_ID = M_PRODUCT_PO.C_BPARTNER_ID
           AND PRODUCT_PO.M_PRODUCT_ID = M_PRODUCT_PO.M_PRODUCT_ID
           AND M_PRODUCT.ISPURCHASED = 'Y'
-      GROUP BY MRP_RUN_PURCHASELINE.M_PRODUCT_ID, M_PRODUCT_PO.CAPACITY, M_PRODUCT_ORG.CAPACITY, M_PRODUCT.CAPACITY,
+      GROUP BY MRP_RUN_PURCHASELINE.M_PRODUCT_ID, M_PRODUCT.NAME, M_PRODUCT_PO.CAPACITY, M_PRODUCT_ORG.CAPACITY, M_PRODUCT.CAPACITY,
         M_PRODUCT_PO.DELIVERYTIME_PROMISED, M_PRODUCT_ORG.DELAYMIN, M_PRODUCT.DELAYMIN,
         M_PRODUCT_PO.QTYTYPE, M_PRODUCT_ORG.QTYTYPE, M_PRODUCT_ORG.QTYTYPE,
         M_PRODUCT_PO.ORDER_MIN, M_PRODUCT_ORG.QTYMIN, M_PRODUCT_ORG.QTYMIN,
@@ -133,6 +133,10 @@
               v_Qty_new := CEIL(v_qty_new/Cur_PlanProduct.qtystd)*Cur_PlanProduct.qtystd;
             END IF;
 
+            IF (Cur_PlanProduct.CAPACITY = 0) THEN
+		RAISE_APPLICATION_ERROR(-20000, '@CapacityZero@ ' || Cur_PlanProduct.PRODUCTNAME);
+            END IF;
+
             v_plannedorderdate_new := TRUNC(v_planneddate_new -
                                       GREATEST(Cur_PlanProduct.DELAYMIN, (CASE WHEN Cur_PlanProduct.CAPACITY IS NULL THEN 0
                                                                   ELSE CEIL(v_Qty_new/Cur_PlanProduct.CAPACITY)
@@ -148,6 +152,10 @@
               v_Qty_new := CEIL(v_qty_new/Cur_PlanProduct.qtystd)*Cur_PlanProduct.qtystd;
             END IF;
 
+            IF (Cur_PlanProduct.CAPACITY = 0) THEN
+		RAISE_APPLICATION_ERROR(-20000, '@CapacityZero@ ' || Cur_PlanProduct.PRODUCTNAME);
+            END IF;
+
             v_plannedorderdate_new := TRUNC(v_planneddate_old -
                                       GREATEST(Cur_PlanProduct.DELAYMIN, (CASE WHEN Cur_PlanProduct.CAPACITY IS NULL THEN 0
                                                                   ELSE CEIL(v_Qty_new/Cur_PlanProduct.CAPACITY)
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Jul 22 10:02:25 2010 +0530
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Jul 22 18:22:49 2010 +0200
@@ -31791,6 +31791,17 @@
 <!--8B03AFC7AAEC4EEBB7364F2BB9A80C99-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--8B03AFC7AAEC4EEBB7364F2BB9A80C99--></AD_MESSAGE>
 
+<!--8D490FAC95814DD2BC9C061E9FAC4568--><AD_MESSAGE>
+<!--8D490FAC95814DD2BC9C061E9FAC4568-->  <AD_MESSAGE_ID><![CDATA[8D490FAC95814DD2BC9C061E9FAC4568]]></AD_MESSAGE_ID>
+<!--8D490FAC95814DD2BC9C061E9FAC4568-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--8D490FAC95814DD2BC9C061E9FAC4568-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--8D490FAC95814DD2BC9C061E9FAC4568-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--8D490FAC95814DD2BC9C061E9FAC4568-->  <VALUE><![CDATA[CapacityZero]]></VALUE>
+<!--8D490FAC95814DD2BC9C061E9FAC4568-->  <MSGTEXT><![CDATA[The following product has capacity 0. Please set a proper capacity and run the process again:]]></MSGTEXT>
+<!--8D490FAC95814DD2BC9C061E9FAC4568-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--8D490FAC95814DD2BC9C061E9FAC4568-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--8D490FAC95814DD2BC9C061E9FAC4568--></AD_MESSAGE>
+
 <!--8D7E3ABF6E02498FBCB36040FBCB82AC--><AD_MESSAGE>
 <!--8D7E3ABF6E02498FBCB36040FBCB82AC-->  <AD_MESSAGE_ID><![CDATA[8D7E3ABF6E02498FBCB36040FBCB82AC]]></AD_MESSAGE_ID>
 <!--8D7E3ABF6E02498FBCB36040FBCB82AC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>