0025101: Void shipment fails depending on the delivery rule in the order assigned
authorGaurav Deshmukh <gaurav.deshmukh@openbravo.com>
Tue, 14 Jan 2014 13:21:26 +0530
changeset 21852 304b13b3a917
parent 21851 7fd7b9956af7
child 21853 8b00b87d54e2
0025101: Void shipment fails depending on the delivery rule in the order assigned
src-db/database/model/functions/M_INOUT_POST.xml
--- a/src-db/database/model/functions/M_INOUT_POST.xml	Sun Jan 19 17:04:32 2014 +0530
+++ b/src-db/database/model/functions/M_INOUT_POST.xml	Tue Jan 14 13:21:26 2014 +0530
@@ -105,6 +105,7 @@
     v_goods_blocked VARCHAR2(1):='N';
     v_bpartner_name c_bpartner.name%TYPE;
     v_DocAction VARCHAR2(60);
+    v_voiddoccount NUMBER:=0;
 
   BEGIN
     IF(p_PInstance_ID IS NOT NULL) THEN
@@ -152,8 +153,8 @@
   BEGIN --BODY
   	IF(NOT FINISH_PROCESS) THEN
   	  v_PUser:=v_User;
-      SELECT io.AD_Client_ID, io.AD_Org_ID, io.CreatedBy, io.C_DocType_ID, io.DateAcct, dt.isreturn, io.m_warehouse_id, io.issotrx
-        INTO v_AD_Client_ID, v_AD_Org_ID, v_User, v_DocType_ID, v_DateAcct, v_isreturndoctype, v_M_Warehouse_ID, v_isSoTrx
+      SELECT io.AD_Client_ID, io.AD_Org_ID, io.CreatedBy, io.C_DocType_ID, io.DateAcct, dt.isreturn, io.m_warehouse_id, io.issotrx,docaction
+        INTO v_AD_Client_ID, v_AD_Org_ID, v_User, v_DocType_ID, v_DateAcct, v_isreturndoctype, v_M_Warehouse_ID, v_isSoTrx,v_DocAction
         FROM M_InOut io JOIN c_doctype dt ON io.c_doctype_id = dt.c_doctype_id
         WHERE io.M_InOut_ID=v_Record_ID;
         IF(v_PUser IS NOT NULL) THEN
@@ -178,7 +179,7 @@
         END IF;
       END IF;
 
-      if(v_isreturndoctype = 'N' AND v_isSoTrx = 'Y') then
+      if(v_isreturndoctype = 'N' AND v_isSoTrx = 'Y' and v_DocAction<>'RC') then
         v_message := null;
         for Cur_OrderLine in (
           select c_orderline_id, line
@@ -784,39 +785,47 @@
               END LOOP;
             END;
           ELSE
-            v_ResultStr:='Check delivery rule for sales orders';
-            v_Message_aux:='';
-            v_orderid_old:='0';
-            FOR Cur_Order IN 
-              (SELECT c_order.deliveryrule, m_inoutline.line, c_order.c_order_id,
-                      c_order.documentno, c_orderline.line as orderline
-               FROM M_InOutLine, C_Orderline, C_Order
-               WHERE M_Inoutline.c_orderline_id = c_orderline.c_orderline_id
-                 AND c_orderline.c_order_id = c_order.c_order_id
-                 AND m_inoutline.m_inout_id = cur_inout.m_inout_id
-                 AND ((c_order.deliveryrule = 'O'
-                      AND EXISTS (SELECT 1 FROM C_OrderLine ol
-                                  WHERE ol.C_Order_ID = C_order.c_order_id
-                                    and ol.qtyordered > ol.qtydelivered ))
-                      OR (c_order.deliveryrule = 'L' 
-                          AND c_orderline.qtyordered > c_orderline.qtydelivered))
-               ORDER BY c_order.c_order_id, c_orderline.line) LOOP
-              --Order lines not completely delivered with delivery rule O or L
-              IF (v_orderid_old <> cur_order.c_order_id OR cur_order.deliveryrule <> 'O' ) THEN
-                v_Message_aux := COALESCE(v_Message_aux,'') || '@Shipment@' || ' ' || cur_inout.documentno;
-                v_Message_aux := v_Message_aux || ' ' || '@line@' || ' ' || cur_order.line || ': ';
-                v_Message_aux := v_Message_aux || '@SalesOrderDocumentno@' || cur_order.documentno;
-                IF (cur_order.deliveryrule = 'O') THEN
-                  v_Message_aux := v_Message_aux || ' ' || '@notCompleteDeliveryRuleOrder@' || '<br>';
-                ELSE
-                  v_Message_aux := v_Message_aux || ' ' || '@line@' || ' ' || cur_order.orderline;
-                  v_Message_aux := v_Message_aux || ' ' || '@notCompleteDeliveryRuleLine@' || '<br>';
+            --Void document is created automatically from main document . 
+            --during completion of void document , we have to skip delivery rule for void document .
+            select COALESCE(instr(M_INOUT.Description,'*R*:'),0) 
+            into v_voiddoccount 
+            from M_INOUT
+            where M_INOUT.M_INOUT_id =v_Record_ID;
+            if v_voiddoccount = 0 then
+              v_ResultStr:='Check delivery rule for sales orders';
+              v_Message_aux:='';
+              v_orderid_old:='0';
+              FOR Cur_Order IN 
+                (SELECT c_order.deliveryrule, m_inoutline.line, c_order.c_order_id,
+                        c_order.documentno, c_orderline.line as orderline
+                 FROM M_InOutLine, C_Orderline, C_Order
+                 WHERE M_Inoutline.c_orderline_id = c_orderline.c_orderline_id
+                   AND c_orderline.c_order_id = c_order.c_order_id
+                   AND m_inoutline.m_inout_id = cur_inout.m_inout_id
+                   AND ((c_order.deliveryrule = 'O'
+                        AND EXISTS (SELECT 1 FROM C_OrderLine ol
+                                    WHERE ol.C_Order_ID = C_order.c_order_id
+                                      and ol.qtyordered > ol.qtydelivered ))
+                        OR (c_order.deliveryrule = 'L' 
+                            AND c_orderline.qtyordered > c_orderline.qtydelivered))
+                 ORDER BY c_order.c_order_id, c_orderline.line) LOOP
+                --Order lines not completely delivered with delivery rule O or L
+                IF (v_orderid_old <> cur_order.c_order_id OR cur_order.deliveryrule <> 'O' ) THEN
+                  v_Message_aux := COALESCE(v_Message_aux,'') || '@Shipment@' || ' ' || cur_inout.documentno;
+                  v_Message_aux := v_Message_aux || ' ' || '@line@' || ' ' || cur_order.line || ': ';
+                  v_Message_aux := v_Message_aux || '@SalesOrderDocumentno@' || cur_order.documentno;
+                  IF (cur_order.deliveryrule = 'O') THEN
+                    v_Message_aux := v_Message_aux || ' ' || '@notCompleteDeliveryRuleOrder@' || '<br>';
+                  ELSE
+                    v_Message_aux := v_Message_aux || ' ' || '@line@' || ' ' || cur_order.orderline;
+                    v_Message_aux := v_Message_aux || ' ' || '@notCompleteDeliveryRuleLine@' || '<br>';
+                  END IF;
                 END IF;
+                v_orderid_old := cur_order.c_order_id;
+              END LOOP;
+              IF (v_Message_aux IS NOT NULL AND v_Message_aux <> '') THEN
+                RAISE_APPLICATION_ERROR(-20000, v_Message_aux);
               END IF;
-              v_orderid_old := cur_order.c_order_id;
-            END LOOP;
-            IF (v_Message_aux IS NOT NULL AND v_Message_aux <> '') THEN
-              RAISE_APPLICATION_ERROR(-20000, v_Message_aux);
             END IF;
           END IF;
           -- Close Shipment