[Warehouse]Improvement in m_inout_create.
authorGorka Ion Damián <gorkaion.damian@openbravo.com>
Tue, 23 Oct 2012 14:08:57 +0200
changeset 18658 20d2f53423cc
parent 18657 12768892fc35
child 18659 719f9dba5048
[Warehouse]Improvement in m_inout_create.
src-db/database/model/functions/M_INOUT_CREATE.xml
--- a/src-db/database/model/functions/M_INOUT_CREATE.xml	Tue Oct 23 14:08:37 2012 +0200
+++ b/src-db/database/model/functions/M_INOUT_CREATE.xml	Tue Oct 23 14:08:57 2012 +0200
@@ -387,82 +387,71 @@
               IF (v_IsStocked <> 0) THEN
                 -- check every locator availability and if qty available
                 --  create InOut line, update storage reservation + qty
-                IF ((NOT Cur_Storage_ISOPEN)
-                    OR (v_Product_old<>ol.M_Product_ID
-                        OR v_Warehouse_old<>ol.M_Warehouse_ID
-                        OR v_UOM_old<>ol.C_UOM_ID
-                        OR COALESCE(v_Attribute_old, '0') <> COALESCE(ol.M_AttributeSetInstance_ID, '0')
-                        OR COALESCE(v_Product_UOM_old, '0') <> COALESCE(ol.M_Product_UOM_ID, '0'))
-                        OR v_orderline_old<>ol.c_orderline_id) THEN
-                  v_Product_old := ol.M_Product_ID;
-                  v_Warehouse_old := ol.M_Warehouse_ID;
-                  v_UOM_old := ol.C_UOM_ID;
-                  v_Attribute_old := ol.M_AttributeSetInstance_ID;
-                  v_Product_UOM_old := ol.M_Product_UOM_ID;
-                  v_orderline_old := ol.c_orderline_id;
-                  IF (Cur_Storage_ISOPEN) THEN
-                    CLOSE Cur_Storage;
-                    Cur_Storage_ISOPEN:=false;
+                v_Product_old := ol.M_Product_ID;
+                v_Warehouse_old := ol.M_Warehouse_ID;
+                v_UOM_old := ol.C_UOM_ID;
+                v_Attribute_old := ol.M_AttributeSetInstance_ID;
+                v_Product_UOM_old := ol.M_Product_UOM_ID;
+                v_orderline_old := ol.c_orderline_id;
+                IF (Cur_Storage_ISOPEN) THEN
+                  CLOSE Cur_Storage;
+                  Cur_Storage_ISOPEN:=false;
+                END IF;
+                
+                -- Call M_GET_STOCK
+                DECLARE
+                  v_pinstance_result AD_PInstance.result%TYPE;
+                  v_pinstance_msg AD_PInstance.errormsg%TYPE;
+                  v_warehouse_rule_id VARCHAR2(32);
+                BEGIN
+                  v_pinstance_id := get_uuid();
+                  INSERT INTO ad_pinstance (
+                      ad_pinstance_id, ad_process_id, record_id, isactive, 
+                      ad_user_id, ad_client_id, ad_org_id, created, createdby,
+                      updated, updatedby
+                  ) VALUES (
+                      v_pinstance_id, 'FF80818132C964E30132C9747257002E', v_record_id, 'Y',
+                      v_User_ID, v_ad_client_id, ol.AD_Org_ID, now(), v_User_ID,
+                      now(), v_User_ID
+                  );
+    
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '10', 'AD_Client_ID', v_ad_client_id, null, null, null, null, null);
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '20', 'AD_Org_ID', Cur_Order.AD_Org_ID, null, null, null, null, null);
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '30', 'M_Product_ID', v_Product_old, null, null, null, null, null);
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '40', 'C_Uom_ID', v_UOM_old, null, null, null, null, null);
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '50', 'M_Product_Uom_ID', v_Product_UOM_old, null, null, null, null, null);
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '60', 'M_Warehouse_ID', v_Warehouse_old, null, null, null, null, null);
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '70', 'M_AttributesetInstance_ID', v_Attribute_old, null, null, null, null, null);
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '80', 'Quantity', null, null, v_Qty, null, null, null);
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '90', 'ProcessID', '118', null, null, null, null, null);
+
+                  SELECT m_warehouse_rule_id INTO v_warehouse_rule_id
+                  FROM c_orderline
+                  WHERE c_orderline_id = ol.c_orderline_id;
+                  AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '100', 'M_Warehouse_Rule_ID', v_warehouse_rule_id, null, null, null, null, null);
+
+                  M_GET_STOCK(v_pinstance_ID, 'N');
+                  -- Check result
+                  SELECT result, errormsg
+                    INTO v_pinstance_result, v_pinstance_msg
+                  FROM ad_pinstance
+                  WHERE ad_pinstance_id = v_pinstance_id;
+                  IF (v_pinstance_result = 0) THEN
+                    -- Error on m_get_stock
+                    RAISE_APPLICATION_ERROR(-20000, v_pinstance_msg);
                   END IF;
-                  
-                  -- Call M_GET_STOCK
-                  DECLARE
-                    v_pinstance_result AD_PInstance.result%TYPE;
-                    v_pinstance_msg AD_PInstance.errormsg%TYPE;
-                    v_warehouse_rule_id VARCHAR2(32);
-                  BEGIN
-                    v_pinstance_id := get_uuid();
-                    INSERT INTO ad_pinstance (
-                        ad_pinstance_id, ad_process_id, record_id, isactive, 
-                        ad_user_id, ad_client_id, ad_org_id, created, createdby,
-                        updated, updatedby
-                    ) VALUES (
-                        v_pinstance_id, 'FF80818132C964E30132C9747257002E', v_record_id, 'Y',
-                        v_User_ID, v_ad_client_id, ol.AD_Org_ID, now(), v_User_ID,
-                        now(), v_User_ID
-                    );
-      
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '10', 'AD_Client_ID', v_ad_client_id, null, null, null, null, null);
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '20', 'AD_Org_ID', Cur_Order.AD_Org_ID, null, null, null, null, null);
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '30', 'M_Product_ID', v_Product_old, null, null, null, null, null);
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '40', 'C_Uom_ID', v_UOM_old, null, null, null, null, null);
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '50', 'M_Product_Uom_ID', v_Product_UOM_old, null, null, null, null, null);
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '60', 'M_Warehouse_ID', v_Warehouse_old, null, null, null, null, null);
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '70', 'M_AttributesetInstance_ID', v_Attribute_old, null, null, null, null, null);
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '80', 'Quantity', null, null, v_Qty, null, null, null);
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '90', 'ProcessID', '118', null, null, null, null, null);
-
-                    SELECT m_warehouse_rule_id INTO v_warehouse_rule_id
-                    FROM c_orderline
-                    WHERE c_orderline_id = ol.c_orderline_id;
-                    AD_PINSTANCE_PARA_INSERT(v_pinstance_id, '100', 'M_Warehouse_Rule_ID', v_warehouse_rule_id, null, null, null, null, null);
-
-                    M_GET_STOCK(v_pinstance_ID, 'N');
-                    -- Check result
-                    SELECT result, errormsg
-                      INTO v_pinstance_result, v_pinstance_msg
-                    FROM ad_pinstance
-                    WHERE ad_pinstance_id = v_pinstance_id;
-                    IF (v_pinstance_result = 0) THEN
-                      -- Error on m_get_stock
-                      RAISE_APPLICATION_ERROR(-20000, v_pinstance_msg);
-                    END IF;
-                  END; -- End Call M_GET_STOCK
-                  
-                  
-                  OPEN Cur_Storage(v_pinstance_id) ;
-                  Cur_Storage_ISOPEN:=true;
-                  FETCH Cur_Storage INTO v_storage;
-                  IF (Cur_Storage%NOTFOUND) THEN
-                    NEXT_PRODUCT:=true;
-                    CLOSE Cur_Storage;
-                    Cur_Storage_ISOPEN:=false;
-                  END IF;
-                  IF (NOT NEXT_PRODUCT) THEN
-                    v_QtyStorage:=v_storage.QtyOnHand;
-                  END IF;--NEXT_PRODUCT
+                END; -- End Call M_GET_STOCK
+                
+                OPEN Cur_Storage(v_pinstance_id) ;
+                Cur_Storage_ISOPEN:=true;
+                FETCH Cur_Storage INTO v_storage;
+                IF (Cur_Storage%NOTFOUND) THEN
+                  NEXT_PRODUCT:=true;
+                  CLOSE Cur_Storage;
+                  Cur_Storage_ISOPEN:=false;
                 END IF;
                 IF (NOT NEXT_PRODUCT) THEN
+                  v_QtyStorage:=v_storage.QtyOnHand;
                   LOOP
                     -- How much do we deliver from here?
                     v_ResultStr:='Deliver';