svn commit: r563823 - in /ofbiz/trunk/applications/manufacturing: servicedef/ src/org/ofbiz/manufacturing/bom/ src/org/ofbiz/manufacturing/jobshopmgt/

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

svn commit: r563823 - in /ofbiz/trunk/applications/manufacturing: servicedef/ src/org/ofbiz/manufacturing/bom/ src/org/ofbiz/manufacturing/jobshopmgt/

jacopoc
Author: jacopoc
Date: Wed Aug  8 04:56:39 2007
New Revision: 563823

URL: http://svn.apache.org/viewvc?view=rev&rev=563823
Log:
Misc fixes and improvements to the services related to production run creation:
- better error handling
- fixes for npe
- better handling of production runs for products that can be manufactured or purchased: if a manual production run is issued, and we have enough information for the manufacturing process, ignore the supplier product info
- fix for a complex date related issue happening when a production run for a product with WIP (Work In Process) components was issued: from a requirement: the start date of the requirement could be wrong

Modified:
    ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml
    ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java
    ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java
    ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.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?view=diff&rev=563823&r1=563822&r2=563823
==============================================================================
--- ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml (original)
+++ ofbiz/trunk/applications/manufacturing/servicedef/services_production_run.xml Wed Aug  8 04:56:39 2007
@@ -50,6 +50,7 @@
         <attribute name="workEffortName" type="String" mode="IN" optional="true"/>
         <attribute name="description" type="String" mode="IN" optional="true"/>
         <attribute name="productionRunId" type="String" mode="OUT" optional="false"/>
+        <attribute name="estimatedCompletionDate" type="java.sql.Timestamp" mode="OUT" optional="true"/>
     </service>
     <service name="updateProductionRun" engine="java"
             location="org.ofbiz.manufacturing.jobshopmgt.ProductionRunServices" invoke="updateProductionRun" auth="true">

Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java?view=diff&rev=563823&r1=563822&r2=563823
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java Wed Aug  8 04:56:39 2007
@@ -499,15 +499,26 @@
         }
     }
 
-    public String createManufacturingOrder(String facilityId, Date date, String workEffortName, String description, String routingId, String orderId, String orderItemSeqId, String shipmentId, boolean useSubstitute) throws GenericEntityException {
+    public Map createManufacturingOrder(String facilityId, Date date, String workEffortName, String description, String routingId, String orderId, String orderItemSeqId, String shipmentId, boolean useSubstitute, boolean ignoreSupplierProducts) throws GenericEntityException {
         String productionRunId = null;
-        if (isManufactured()) {
+        Timestamp endDate = null;
+        if (isManufactured(ignoreSupplierProducts)) {
             BOMNode oneChildNode = null;
             ArrayList childProductionRuns = new ArrayList();
+            Timestamp maxEndDate = null;
             for (int i = 0; i < childrenNodes.size(); i++) {
                 oneChildNode = (BOMNode)childrenNodes.get(i);
                 if (oneChildNode != null) {
-                    String childProductionRunId = oneChildNode.createManufacturingOrder(facilityId, date, null, null, null, null, null, shipmentId, false);
+                    Map tmpResult = oneChildNode.createManufacturingOrder(facilityId, date, null, null, null, null, null, shipmentId, false, false);
+                    String childProductionRunId = (String)tmpResult.get("productionRunId");
+                    Timestamp childEndDate = (Timestamp)tmpResult.get("endDate");
+                    if (maxEndDate == null) {
+                        maxEndDate = childEndDate;
+                    }
+                    if (childEndDate != null && maxEndDate.compareTo(childEndDate) < 0) {
+                        maxEndDate = childEndDate;
+                    }
+
                     if (childProductionRunId != null) {
                         childProductionRuns.add(childProductionRunId);
                     }
@@ -540,12 +551,17 @@
             }
             
             serviceContext.put("pRQuantity", new Double(getQuantity()));
-            serviceContext.put("startDate", startDate);
+            if (UtilValidate.isNotEmpty(maxEndDate)) {
+                serviceContext.put("startDate", maxEndDate);
+            } else {
+                serviceContext.put("startDate", startDate);
+            }
             serviceContext.put("userLogin", userLogin);
             Map resultService = null;
             try {
                 resultService = dispatcher.runSync("createProductionRun", serviceContext);
                 productionRunId = (String)resultService.get("productionRunId");
+                endDate = (Timestamp)resultService.get("estimatedCompletionDate");
             } catch (GenericServiceException e) {
                 Debug.logError("Problem calling the createProductionRun service", module);
             }
@@ -562,7 +578,7 @@
                 //Debug.logError(e, "Problem calling the getManufacturingComponents service", module);
             }
         }
-        return productionRunId;
+        return UtilMisc.toMap("productionRunId", productionRunId, "endDate", endDate);
     }
 
     public Timestamp getStartDate(String facilityId, Timestamp requiredBydate, boolean allNodes) {
@@ -620,7 +636,7 @@
         return isWarehouseManaged;
     }
 
-    public boolean isManufactured() {
+    public boolean isManufactured(boolean ignoreSupplierProducts) {
         List supplierProducts = null;
         try {
             supplierProducts = product.getRelated("SupplierProduct", UtilMisc.toMap("supplierPrefOrderId", "10_MAIN_SUPPL"), UtilMisc.toList("minimumOrderQuantity"));
@@ -628,7 +644,10 @@
             Debug.logError("Problem in BOMNode.isManufactured()", module);
         }
         supplierProducts = EntityUtil.filterByDate(supplierProducts, UtilDateTime.nowTimestamp(), "availableFromDate", "availableThruDate", true);
-        return childrenNodes.size() > 0 && UtilValidate.isEmpty(supplierProducts);
+        return childrenNodes.size() > 0 && (ignoreSupplierProducts || UtilValidate.isEmpty(supplierProducts));
+    }
+    public boolean isManufactured() {
+        return isManufactured(false);
     }
     
     public boolean isVirtual() {

Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java?view=diff&rev=563823&r1=563822&r2=563823
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java Wed Aug  8 04:56:39 2007
@@ -23,6 +23,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
@@ -345,7 +346,8 @@
                     facilityId = shipment.getString("originFacilityId");
                 }
             }
-            workEffortId = root.createManufacturingOrder(facilityId, date, workEffortName, description, routingId, orderId, orderItemSeqId, shipmentId, true);
+            Map tmpMap = root.createManufacturingOrder(facilityId, date, workEffortName, description, routingId, orderId, orderItemSeqId, shipmentId, true, true);
+            workEffortId = (String)tmpMap.get("productionRunId");
         }
         return workEffortId;
     }

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?view=diff&rev=563823&r1=563822&r2=563823
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Wed Aug  8 04:56:39 2007
@@ -432,6 +432,7 @@
             Debug.logError(e, "Problem calling the updateWorkEffort service", module);
         }
         result.put("productionRunId", productionRunId);
+        result.put("estimatedCompletionDate", startDate);
         result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "ManufacturingProductionRunCreated",UtilMisc.toMap("productionRunId", productionRunId), locale));
         return result;
     }
@@ -1848,8 +1849,12 @@
         try {
             resultService = dispatcher.runSync("createProductionRunsForProductBom", serviceContext);
         } catch (GenericServiceException e) {
-            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale));
+            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunNotCreated", locale) + ": " + e.getMessage());
+        }
+        if (ServiceUtil.isError(resultService)) {
+            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(resultService));
         }
+
         String productionRunId = (String)resultService.get("productionRunId");
         result.put("productionRunId", productionRunId);
 
@@ -2149,6 +2154,9 @@
         String description = (String)context.get("description");
         String routingId = (String)context.get("routingId");
         String workEffortId = null;
+        if (quantity == null) {
+            quantity = new Double(1.0);
+        }
         try {
             ArrayList components = new ArrayList();
             BOMTree tree = new BOMTree(productId, "MANUF_COMPONENT", startDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin);
@@ -2158,6 +2166,9 @@
             workEffortId = tree.createManufacturingOrders(facilityId, startDate, workEffortName, description, routingId, null, null, null, userLogin);
         } catch(GenericEntityException gee) {
             return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage());
+        }
+        if (workEffortId == null) {
+            return ServiceUtil.returnError("No production run is required for product with id [" + productId +"] in date [" + startDate + "]; please verify the validity dates of the bill of materials and routing.");
         }
         ArrayList productionRuns = new ArrayList();
         result.put("productionRuns" , productionRuns);