svn commit: r590004 - in /ofbiz/trunk/applications: manufacturing/servicedef/ manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ order/src/org/ofbiz/order/order/ order/src/org/ofbiz/order/shoppingcart/

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

svn commit: r590004 - in /ofbiz/trunk/applications: manufacturing/servicedef/ manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ order/src/org/ofbiz/order/order/ order/src/org/ofbiz/order/shoppingcart/

lektran
Author: lektran
Date: Tue Oct 30 02:34:58 2007
New Revision: 590004

URL: http://svn.apache.org/viewvc?rev=590004&view=rev
Log:
A few changes to the way auto marketing packages are handled:
1.  No longer producing for the current order only, all orders are taken into account, so we're now trying to produce whatever will get the ATP back to zero.
2.  Only producing what the available components will allow, ie. if we need to produce 10 units but only have enough components for 5 then that's all we'll produce.
3.  Because of (1) no longer associating the production run to the order item via WorkOrderItemFulfillment.
4.  Moved the call to createProductionRunForMktgPackage so that it is called when an order is edited as well (Fixes OFBIZ-714, the marketing package was decomposed when cancelling inventory reservations but not reproduced afterwards).

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

Modified: ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml?rev=590004&r1=590003&r2=590004&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml (original)
+++ ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml Tue Oct 30 02:34:58 2007
@@ -307,9 +307,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/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=590004&r1=590003&r2=590004&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 Tue Oct 30 02:34:58 2007
@@ -2102,7 +2102,7 @@
         String facilityId = (String)context.get("facilityId");
         String orderId = (String)context.get("orderId");
         String orderItemSeqId = (String)context.get("orderItemSeqId");
-        
+
         GenericValue orderItem = null;
         try {
             orderItem = delegator.findByPrimaryKey("OrderItem", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId));
@@ -2126,37 +2126,32 @@
             }
 
             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("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);
-            
-                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());
-                }
-                // only complete the production run if we have enough components available to produce the desired amount, otherwise errors will result
-                serviceContext.remove("pRQuantity");
-                serviceContext.remove("startDate");
-                resultService = dispatcher.runSync("getMktgPackagesAvailable", serviceContext);
+                Map resultService = dispatcher.runSync("getMktgPackagesAvailable", serviceContext);
                 double mktgPackagesAvailable = ((Double) resultService.get("availableToPromiseTotal")).doubleValue();
-                if (mktgPackagesAvailable > qtyToProduce) {
+
+                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("workEffortName", "");
+
+                    resultService = dispatcher.runSync("createProductionRun", serviceContext);
+
+                    String productionRunId = (String)resultService.get("productionRunId");
+                    result.put("productionRunId", productionRunId);
+
                     try {
                         serviceContext.clear();
                         serviceContext.put("productionRunId", productionRunId);
@@ -2170,12 +2165,15 @@
                     } catch (GenericServiceException e) {
                         return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale));
                     }
-                }
-                result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunCreated", UtilMisc.toMap("productionRunId", productionRunId), locale));
-                return result;
 
+                    result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunCreated", UtilMisc.toMap("productionRunId", productionRunId), locale));
+                    return result;
+                } else {
+                    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("Order item [" + orderItem + "] does not need to be produced - ATP is [" + existingAtp + "]", module); }
+                if (Debug.verboseOn()) { Debug.logVerbose("No marketing packages need to be produced - ATP is [" + existingAtp + "]", module); }
                 return ServiceUtil.returnSuccess();
             }
         } catch (GenericServiceException e) {

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=590004&r1=590003&r2=590004&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 Tue Oct 30 02:34:58 2007
@@ -1150,6 +1150,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/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java?rev=590004&r1=590003&r2=590004&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Tue Oct 30 02:34:58 2007
@@ -628,17 +628,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);