svn commit: r601627 - in /ofbiz/trunk/applications: manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java order/src/org/ofbiz/order/order/OrderServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r601627 - in /ofbiz/trunk/applications: manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java order/src/org/ofbiz/order/order/OrderServices.java

lektran
Author: lektran
Date: Wed Dec  5 22:16:37 2007
New Revision: 601627

URL: http://svn.apache.org/viewvc?rev=601627&view=rev
Log:
Auto marketing packages are now produced for immediately fulfilled orders

Modified:
    ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=601627&r1=601626&r2=601627&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Wed Dec  5 22:16:37 2007
@@ -2113,6 +2113,17 @@
         String facilityId = (String)context.get("facilityId");
         String orderId = (String)context.get("orderId");
         String orderItemSeqId = (String)context.get("orderItemSeqId");
+        
+        // Check if the order is to be immediately fulfilled, in which case the inventory
+        // hasn't been reserved and ATP not yet decreased
+        boolean isImmediatelyFulfilled = false;
+        try {
+            GenericValue order = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
+            GenericValue productStore = delegator.getRelatedOne("ProductStore", order);
+            isImmediatelyFulfilled = "Y".equals(productStore.getString("isImmediatelyFulfilled"));
+        } catch (GenericEntityException e) {
+            return ServiceUtil.returnError("Error creating a production run for marketing package for order [" + orderId + " " + orderItemSeqId + "]: " + e.getMessage());
+        }
 
         GenericValue orderItem = null;
         try {
@@ -2135,7 +2146,11 @@
             if (tmpResults.get("availableToPromiseTotal") != null) {
                 existingAtp = ((Double) tmpResults.get("availableToPromiseTotal")).doubleValue();
             }
-
+            // if the order is immediately fulfilled, adjust the atp to compensate for it not reserved
+            if (isImmediatelyFulfilled) {
+                existingAtp -= orderItem.getDouble("quantity");
+            }
+            
             if (Debug.verboseOn()) { Debug.logVerbose("Order item [" + orderItem + "] Existing ATP = [" + existingAtp + "]", module); }
             // we only need to produce more marketing packages if there isn't enough in stock.
             if (existingAtp < 0.0) {

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=601627&r1=601626&r2=601627&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Wed Dec  5 22:16:37 2007
@@ -1066,35 +1066,34 @@
             reserveInventory = false;
         }
 
-        if (reserveInventory) {
-            // START inventory reservation
-            // decrement inventory available for each OrderItemShipGroupAssoc, within the same transaction
-            if (orderItemShipGroupInfo != null && orderItemShipGroupInfo.size() > 0) {
-                Iterator osiInfos = orderItemShipGroupInfo.iterator();
-                while (osiInfos.hasNext()) {
-                    GenericValue orderItemShipGroupAssoc = (GenericValue) osiInfos.next();
-                    if ("OrderItemShipGroupAssoc".equals(orderItemShipGroupAssoc.getEntityName())) {
-                        if (dropShipGroupIds != null && dropShipGroupIds.contains(orderItemShipGroupAssoc.getString("shipGroupSeqId"))) {
-                            // the items in the drop ship groups are not reserved
-                            continue;
-                        }
-                        GenericValue orderItem = (GenericValue) itemValuesBySeqId.get(orderItemShipGroupAssoc.get("orderItemSeqId"));
-                        String itemStatus = orderItem.getString("statusId");
-                        if ("ITEM_REJECTED".equals(itemStatus) || "ITEM_CANCELLED".equals(itemStatus) || "ITEM_COMPLETED".equals(itemStatus)) {
-                            Debug.logInfo("Order item [" + orderItem.getString("orderId") + " / " + orderItem.getString("orderItemSeqId") + "] is not in a proper status for reservation", module);
-                            continue;
-                        }
-                        if (UtilValidate.isNotEmpty(orderItem.getString("productId")) &&   // only reserve product items, ignore non-product items
+        // START inventory reservation
+        // decrement inventory available for each OrderItemShipGroupAssoc, within the same transaction
+        if (orderItemShipGroupInfo != null && orderItemShipGroupInfo.size() > 0) {
+            Iterator osiInfos = orderItemShipGroupInfo.iterator();
+            while (osiInfos.hasNext()) {
+                GenericValue orderItemShipGroupAssoc = (GenericValue) osiInfos.next();
+                if ("OrderItemShipGroupAssoc".equals(orderItemShipGroupAssoc.getEntityName())) {
+                    if (dropShipGroupIds != null && dropShipGroupIds.contains(orderItemShipGroupAssoc.getString("shipGroupSeqId"))) {
+                        // the items in the drop ship groups are not reserved
+                        continue;
+                    }
+                    GenericValue orderItem = (GenericValue) itemValuesBySeqId.get(orderItemShipGroupAssoc.get("orderItemSeqId"));
+                    String itemStatus = orderItem.getString("statusId");
+                    if ("ITEM_REJECTED".equals(itemStatus) || "ITEM_CANCELLED".equals(itemStatus) || "ITEM_COMPLETED".equals(itemStatus)) {
+                        Debug.logInfo("Order item [" + orderItem.getString("orderId") + " / " + orderItem.getString("orderItemSeqId") + "] is not in a proper status for reservation", module);
+                        continue;
+                    }
+                    if (UtilValidate.isNotEmpty(orderItem.getString("productId")) &&   // only reserve product items, ignore non-product items
                             !"RENTAL_ORDER_ITEM".equals(orderItem.getString("orderItemTypeId"))) {  // ignore for rental
-                            try {
-                                // get the product of the order item
-                                GenericValue product = orderItem.getRelatedOne("Product");
-                                if (product == null) {
-                                    Debug.logError("Error when looking up product in reserveInventory service", module);
-                                    resErrorMessages.add("Error when looking up product in reserveInventory service");
-                                    continue;
-                                }
-                                
+                        try {
+                            // get the product of the order item
+                            GenericValue product = orderItem.getRelatedOne("Product");
+                            if (product == null) {
+                                Debug.logError("Error when looking up product in reserveInventory service", module);
+                                resErrorMessages.add("Error when looking up product in reserveInventory service");
+                                continue;
+                            }
+                            if (reserveInventory) {
                                 // for MARKETING_PKG_PICK reserve the components
                                 if ("MARKETING_PKG_PICK".equals(product.get("productTypeId"))) {
                                     Map componentsRes = dispatcher.runSync("getAssociatedProducts", UtilMisc.toMap("productId", orderItem.getString("productId"), "type", "PRODUCT_COMPONENT"));
@@ -1150,27 +1149,28 @@
                                         invErrMsg += " with ID " + orderItem.getString("productId") + " is no longer in stock. Please try reducing the quantity or removing the product from this order.";
                                         resErrorMessages.add(invErrMsg);
                                     }
-                                    // If the product is a marketing package auto, attempt to create enough packages to bring ATP back to 0, won't necessarily create enough to cover this order.
-                                    if ("MARKETING_PKG_AUTO".equals(product.get("productTypeId"))) {
-                                        // do something tricky here: run as the "system" user
-                                        // that can actually create and run a production run
-                                        GenericValue permUserLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "system"));
-                                        Map inputMap = new HashMap();
-                                        inputMap.put("facilityId", productStore.getString("inventoryFacilityId"));
-                                        inputMap.put("orderId", orderItem.getString("orderId"));
-                                        inputMap.put("orderItemSeqId", orderItem.getString("orderItemSeqId"));
-                                        inputMap.put("userLogin", permUserLogin);
-                                        Map prunResult = dispatcher.runSync("createProductionRunForMktgPkg", inputMap);
-                                        if (ServiceUtil.isError(prunResult)) {
-                                            Debug.logError(ServiceUtil.getErrorMessage(prunResult) + " for input:" + inputMap, module);
-                                        }
-                                    }
                                 }
-                            } catch (GenericServiceException e) {
-                                String errMsg = "Fatal error calling reserveStoreInventory service: " + e.toString();
-                                Debug.logError(e, errMsg, module);
-                                resErrorMessages.add(errMsg);
                             }
+                            // Reserving inventory or not we still need to create a marketing package
+                            // If the product is a marketing package auto, attempt to create enough packages to bring ATP back to 0, won't necessarily create enough to cover this order.
+                            if ("MARKETING_PKG_AUTO".equals(product.get("productTypeId"))) {
+                                // do something tricky here: run as the "system" user
+                                // that can actually create and run a production run
+                                GenericValue permUserLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "system"));
+                                Map inputMap = new HashMap();
+                                inputMap.put("facilityId", productStore.getString("inventoryFacilityId"));
+                                inputMap.put("orderId", orderItem.getString("orderId"));
+                                inputMap.put("orderItemSeqId", orderItem.getString("orderItemSeqId"));
+                                inputMap.put("userLogin", permUserLogin);
+                                Map prunResult = dispatcher.runSync("createProductionRunForMktgPkg", inputMap);
+                                if (ServiceUtil.isError(prunResult)) {
+                                    Debug.logError(ServiceUtil.getErrorMessage(prunResult) + " for input:" + inputMap, module);
+                                }
+                            }
+                        } catch (GenericServiceException e) {
+                            String errMsg = "Fatal error calling reserveStoreInventory service: " + e.toString();
+                            Debug.logError(e, errMsg, module);
+                            resErrorMessages.add(errMsg);
                         }
                     }
                 }