You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2008/01/14 00:22:37 UTC

svn commit: r611674 - in /ofbiz/branches/release4.0/applications: manufacturing/servicedef/ manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ order/src/org/ofbiz/order/order/ order/src/org/ofbiz/order/shoppingcart/

Author: jleroux
Date: Sun Jan 13 15:22:35 2008
New Revision: 611674

URL: http://svn.apache.org/viewvc?rev=611674&view=rev
Log:
As it was not "mergeable" automatically, I merged (trunk) revision 590004 by hand

Modified:
    ofbiz/branches/release4.0/applications/manufacturing/servicedef/services_production_run.xml
    ofbiz/branches/release4.0/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
    ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderServices.java
    ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java

Modified: ofbiz/branches/release4.0/applications/manufacturing/servicedef/services_production_run.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/manufacturing/servicedef/services_production_run.xml?rev=611674&r1=611673&r2=611674&view=diff
==============================================================================
--- ofbiz/branches/release4.0/applications/manufacturing/servicedef/services_production_run.xml (original)
+++ ofbiz/branches/release4.0/applications/manufacturing/servicedef/services_production_run.xml Sun Jan 13 15:22:35 2008
@@ -298,9 +298,9 @@
     </service>
     <service name="createProductionRunForMktgPkg" engine="java"
             location="org.ofbiz.manufacturing.jobshopmgt.ProductionRunServices" invoke="createProductionRunForMktgPkg" auth="true">
-        <description>Creates a production run for a marketing package when the ordered item is out of stock (ATP quantity less than zero.)  
-                The quantity produced is either the quantity ordered or to bring total ATP quantity of the product back up to zero,
-                whichever is less.</description>
+        <description>Creates a production run for a marketing package when the product is out of stock (ATP quantity less than zero.)  
+                Attempts to produce enough to bring total ATP quantity of the product back up to zero, but will only produce what is
+                available based on the components required.</description>
         <attribute mode="IN" name="orderId" optional="false" type="String"/>
         <attribute mode="IN" name="orderItemSeqId" optional="false" type="String"/>
         <attribute mode="IN" name="facilityId" optional="false" type="String"/>

Modified: ofbiz/branches/release4.0/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=611674&r1=611673&r2=611674&view=diff
==============================================================================
--- ofbiz/branches/release4.0/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original)
+++ ofbiz/branches/release4.0/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Sun Jan 13 15:22:35 2008
@@ -1979,32 +1979,33 @@
             }
 
             if (Debug.verboseOn()) { Debug.logVerbose("Order item [" + orderItem + "] Existing ATP = [" + existingAtp + "]", module); } 
-            // we only need to produce more marketing packages if it is out of stock.  note that the ATP quantity already includes this order item
+            // we only need to produce more marketing packages if there isn't enough in stock.
             if (existingAtp < 0.0) {
-                // how much should we produce?  If there already is some inventory, then just produce enough to bring ATP back up to zero, which may be less than the quantity ordered.
-                // Otherwise, the ATP might be more negative due to previous orders, so just produce the quantity on this order
-                double qtyToProduce = Math.min((0 - existingAtp), orderItem.getDouble("quantity").doubleValue());
-                if (Debug.verboseOn()) { Debug.logVerbose("Order quantity = [" + orderItem.getDouble("quantity").doubleValue() + "] quantity to produce = [" + qtyToProduce + "]", module); }
-
+                // how many should we produce?  If there already is some inventory, then just produce enough to bring ATP back up to zero.
+                double qtyRequired = 0 - existingAtp;
+                // ok so that's how many we WANT to produce, but let's check how many we can actually produce based on the available components
                 Map serviceContext = new HashMap();
                 serviceContext.put("productId", orderItem.getString("productId"));
+                serviceContext.put("facilityId", facilityId);
+                serviceContext.put("userLogin", userLogin);
+                Map resultService = dispatcher.runSync("getMktgPackagesAvailable", serviceContext);
+                double mktgPackagesAvailable = ((Double) resultService.get("availableToPromiseTotal")).doubleValue();
+
+                double qtyToProduce = Math.min(qtyRequired, mktgPackagesAvailable);
+
+                if (qtyToProduce > 0) {
+                    if (Debug.verboseOn()) { Debug.logVerbose("Required quantity (all orders) = [" + qtyRequired + "] quantity to produce = [" + qtyToProduce + "]", module); }
+
                 serviceContext.put("pRQuantity", new Double(qtyToProduce));
                 serviceContext.put("startDate", UtilDateTime.nowTimestamp());
-                serviceContext.put("facilityId", facilityId);
                 //serviceContext.put("workEffortName", "");
-                serviceContext.put("userLogin", userLogin);
                 
-                Map resultService = dispatcher.runSync("createProductionRun", serviceContext);
+                    resultService = dispatcher.runSync("createProductionRun", serviceContext);
             
                 String productionRunId = (String)resultService.get("productionRunId");
                 result.put("productionRunId", productionRunId);
 
                 try {
-                    delegator.create("WorkOrderItemFulfillment", UtilMisc.toMap("workEffortId", productionRunId, "orderId", orderId, "orderItemSeqId", orderItemSeqId));
-                } catch (GenericEntityException e) {
-                    return ServiceUtil.returnError("Error creating a production run for marketing package for order [" + orderId + " " + orderItemSeqId + "]: " + e.getMessage());
-                }
-                try {
                     serviceContext.clear();
                     serviceContext.put("productionRunId", productionRunId);
                     serviceContext.put("statusId", "PRUN_COMPLETED");
@@ -2022,7 +2023,11 @@
                 return result;
 
             } else {
-                if (Debug.verboseOn()) { Debug.logVerbose("Order item [" + orderItem + "] does not need to be produced - ATP is [" + existingAtp + "]", module); }
+                    if (Debug.verboseOn()) { Debug.logVerbose("There are not enough components available to produce any marketing packages [" + orderItem.getString("productId") + "]", module); }
+                    return ServiceUtil.returnSuccess();
+                }
+            } else {
+                if (Debug.verboseOn()) { Debug.logVerbose("No marketing packages need to be produced - ATP is [" + existingAtp + "]", module); }
                 return ServiceUtil.returnSuccess();
             }
         } catch (GenericServiceException e) {

Modified: ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=611674&r1=611673&r2=611674&view=diff
==============================================================================
--- ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/order/OrderServices.java Sun Jan 13 15:22:35 2008
@@ -1059,6 +1059,21 @@
                                     }
                                     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();

Modified: ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java?rev=611674&r1=611673&r2=611674&view=diff
==============================================================================
--- ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java (original)
+++ ofbiz/branches/release4.0/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Sun Jan 13 15:22:35 2008
@@ -620,17 +620,7 @@
                         if (ServiceUtil.isError(prunResult)) {
                             Debug.logError(ServiceUtil.getErrorMessage(prunResult) + " for input:" + inputMap, module);
                         }
-                    } else if ("MARKETING_PKG_AUTO".equals(product.getString("productTypeId"))) {
-                        Map inputMap = new HashMap();
-                        inputMap.put("facilityId", productStore.getString("inventoryFacilityId"));
-                        inputMap.put("orderId", 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 (Exception e) {
                     String service = e.getMessage();
                     Map messageMap = UtilMisc.toMap("service", service);