svn commit: r438286 - in /incubator/ofbiz/trunk/applications/product: servicedef/services_facility.xml src/org/ofbiz/product/inventory/InventoryServices.java

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

svn commit: r438286 - in /incubator/ofbiz/trunk/applications/product: servicedef/services_facility.xml src/org/ofbiz/product/inventory/InventoryServices.java

sichen
Author: sichen
Date: Tue Aug 29 16:19:16 2006
New Revision: 438286

URL: http://svn.apache.org/viewvc?rev=438286&view=rev
Log:
Turned off transactions for all the getInventory_ services -- they do not store anything and should not require them.  Also added marketing package ATP/QOH to the getProductInventorySummaryForItems service which searches across all facilities

Modified:
    incubator/ofbiz/trunk/applications/product/servicedef/services_facility.xml
    incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java

Modified: incubator/ofbiz/trunk/applications/product/servicedef/services_facility.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/product/servicedef/services_facility.xml?rev=438286&r1=438285&r2=438286&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/product/servicedef/services_facility.xml (original)
+++ incubator/ofbiz/trunk/applications/product/servicedef/services_facility.xml Tue Aug 29 16:19:16 2006
@@ -103,7 +103,7 @@
     </service>
 
     <service name="getMktgPackagesAvailable" engine="simple"
-                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getMktgPackagesAvailable" auth="false">
+                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getMktgPackagesAvailable" auth="false" use-transaction="false">
         <description>Get Marketing Packages Available From Components In Inventory</description>
         <attribute name="productId" type="String" mode="IN" optional="false"/>
         <attribute name="facilityId" type="String" mode="IN" optional="true"/>
@@ -111,14 +111,14 @@
         <attribute name="availableToPromiseTotal" type="Double" mode="OUT" optional="false"/>
     </service>
     <service name="getProductInventoryAvailable" engine="simple"
-                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getProductInventoryAvailable" auth="false">
+                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getProductInventoryAvailable" auth="false" use-transaction="false">
         <description>Get Inventory Availability for a Product</description>
         <attribute name="productId" type="String" mode="IN" optional="false"/>
         <attribute name="quantityOnHandTotal" type="Double" mode="OUT" optional="false"/>
         <attribute name="availableToPromiseTotal" type="Double" mode="OUT" optional="false"/>
     </service>
     <service name="getInventoryAvailableByFacility" engine="simple"
-                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getProductInventoryAvailable" auth="false">
+                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getProductInventoryAvailable" auth="false" use-transaction="false">
         <description>Get Inventory Availability for a Product constrained by a facilityId</description>
         <attribute name="productId" type="String" mode="IN" optional="false"/>
         <attribute name="facilityId" type="String" mode="IN" optional="false"/>
@@ -135,7 +135,7 @@
         <attribute name="availableToPromiseTotal" type="Double" mode="OUT" optional="false"/>
     </service>
     <service name="getInventoryAvailableByContainer" engine="simple"
-                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getProductInventoryAvailable" auth="false">
+                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getProductInventoryAvailable" auth="false" use-transaction="false">
         <description>Get Inventory Availability for a Product constrained by a containerId</description>
         <attribute name="productId" type="String" mode="IN" optional="false"/>
         <attribute name="containerId" type="String" mode="IN" optional="false"/>
@@ -143,14 +143,14 @@
         <attribute name="availableToPromiseTotal" type="Double" mode="OUT" optional="false"/>
     </service>
     <service name="getInventoryAvailableByItem" engine="simple"
-                location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getProductInventoryAvailable" auth="false">
+             location="org/ofbiz/product/inventory/InventoryServices.xml" invoke="getProductInventoryAvailable" auth="false" use-transaction="false">
         <description>Get Inventory Availability for an InventoryItem</description>
         <attribute name="inventoryItemId" type="String" mode="IN" optional="false"/>
         <attribute name="quantityOnHandTotal" type="Double" mode="OUT" optional="false"/>
         <attribute name="availableToPromiseTotal" type="Double" mode="OUT" optional="false"/>
     </service>
     <service name="getProductInventoryAvailableFromAssocProducts" engine="java"
-                location="org.ofbiz.product.inventory.InventoryServices" invoke="getProductInventoryAvailableFromAssocProducts" auth="false">
+             location="org.ofbiz.product.inventory.InventoryServices" invoke="getProductInventoryAvailableFromAssocProducts" auth="false" use-transaction="false">
         <description>
             Get Inventory Availability for a product based on List of associated products,
             usually marketing package components.
@@ -161,11 +161,14 @@
         <attribute name="availableToPromiseTotal" type="Double" mode="OUT" optional="false"/>
     </service>
     <service name="getProductInventorySummaryForItems" engine="java"
-                location="org.ofbiz.product.inventory.InventoryServices" invoke="getProductInventorySummaryForItems" auth="false">
-        <description>Get Inventory Availability for a list of OrderItems.</description>
+                location="org.ofbiz.product.inventory.InventoryServices" invoke="getProductInventorySummaryForItems" auth="false" use-transaction="false">
+        <description>Get ATP/QOH Availability for a list of OrderItems by summing over all facilities.  If the item is a MARKETING_PKG_AUTO, then put its quantity available from components
+            in the mktgPkgATPMap and mktgPkgQOHMap.</description>
         <attribute name="orderItems" type="List" mode="IN" optional="false"/>
         <attribute name="quantityOnHandMap" type="Map" mode="OUT" optional="false"/>
         <attribute name="availableToPromiseMap" type="Map" mode="OUT" optional="false"/>
+        <attribute name="mktgPkgQOHMap" type="Map" mode="OUT" optional="false"/>
+        <attribute name="mktgPkgATPMap" type="Map" mode="OUT" optional="false"/>
     </service>
 
     <service name="checkInventoryAvailability" engine="java"

Modified: incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java?rev=438286&r1=438285&r2=438286&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java (original)
+++ incubator/ofbiz/trunk/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java Tue Aug 29 16:19:16 2006
@@ -699,21 +699,19 @@
         result.put("quantityOnHandTotal", quantityOnHandTotal);
         return result;
     }
-    
-    /**
-     * Given a set of order items, returns a hashmap with the ATP and QOH for each product. The default method is to sum
-     * inventories over all Facilities.
-     */
+
+
     public static Map getProductInventorySummaryForItems(DispatchContext dctx, Map context) {
         GenericDelegator delegator = dctx.getDelegator();
         LocalDispatcher dispatcher = dctx.getDispatcher();
         List orderItems = (List) context.get("orderItems");
         Map atpMap = new HashMap();
         Map qohMap = new HashMap();
+        Map mktgPkgAtpMap = new HashMap();
+        Map mktgPkgQohMap = new HashMap();
         Map results = ServiceUtil.returnSuccess();
-        results.put("availableToPromiseMap", atpMap);
-        results.put("quantityOnHandMap", qohMap);
 
+        // get a list of all available facilities for looping
         List facilities = null;
         try {
             facilities = delegator.findAll("Facility");
@@ -722,16 +720,17 @@
             return ServiceUtil.returnError("Unable to locate facilities.");
         }
 
+        // loop through all the order items
         Iterator iter = orderItems.iterator();
         while (iter.hasNext()) {
             GenericValue orderItem = (GenericValue) iter.next();
             String productId = orderItem.getString("productId");
 
             if ((productId == null) || productId.equals("")) continue;
-            
+
             GenericValue product = null;
             try {
-                product = orderItem.getRelatedOne("Product");
+                product = orderItem.getRelatedOneCache("Product");
             } catch (GenericEntityException e) {
                 Debug.logError(e, "Couldn't get product.", module);
                 return ServiceUtil.returnError("Unable to retrive product with id [" + productId + "]");
@@ -739,30 +738,53 @@
 
             double atp = 0.0;
             double qoh = 0.0;
+            double mktgPkgAtp = 0.0;
+            double mktgPkgQoh = 0.0;
             Iterator facilityIter = facilities.iterator();
+
+            // loop through all the facilities
             while (facilityIter.hasNext()) {
                 GenericValue facility = (GenericValue) facilityIter.next();
-                Map params = UtilMisc.toMap("productId", productId, "facilityId", facility.getString("facilityId"));
                 Map invResult = null;
+                Map mktgPkgInvResult = null;
+
+                // get both the real ATP/QOH available and the quantities available from marketing packages
                 try {
                     if ("MARKETING_PKG_AUTO".equals(product.getString("productTypeId"))) {
-                        invResult = dispatcher.runSync("getMktgPackagesAvailable", params);
-                    } else {
-                        invResult = dispatcher.runSync("getInventoryAvailableByFacility", params);
-                    }
+                        mktgPkgInvResult = dispatcher.runSync("getMktgPackagesAvailable", UtilMisc.toMap("productId", productId, "facilityId", facility.getString("facilityId")));
+                    }
+                    invResult = dispatcher.runSync("getInventoryAvailableByFacility", UtilMisc.toMap("productId", productId, "facilityId", facility.getString("facilityId")));
                 } catch (GenericServiceException e) {
                     String msg = "Could not find inventory for facility [" + facility.getString("facilityId") + "]";
                     Debug.logError(e, msg, module);
                     return ServiceUtil.returnError(msg);
                 }
-                Double fatp = (Double) invResult.get("availableToPromiseTotal");
-                Double fqoh = (Double) invResult.get("quantityOnHandTotal");
-                if (fatp != null) atp += fatp.doubleValue();
-                if (fqoh != null) qoh += fqoh.doubleValue();
+
+                // add the results for this facility to the ATP/QOH counter for all facilities
+                if (!ServiceUtil.isError(invResult)) {
+                    Double fatp = (Double) invResult.get("availableToPromiseTotal");
+                    Double fqoh = (Double) invResult.get("quantityOnHandTotal");
+                    if (fatp != null) atp += fatp.doubleValue();
+                    if (fqoh != null) qoh += fqoh.doubleValue();
+                }
+                if (("MARKETING_PKG_AUTO".equals(product.getString("productTypeId"))) && (!ServiceUtil.isError(mktgPkgInvResult))) {
+                    Double fatp = (Double) mktgPkgInvResult.get("availableToPromiseTotal");
+                    Double fqoh = (Double) mktgPkgInvResult.get("quantityOnHandTotal");
+                    if (fatp != null) mktgPkgAtp += fatp.doubleValue();
+                    if (fqoh != null) mktgPkgQoh += fqoh.doubleValue();
+                }
             }
+
             atpMap.put(productId, new Double(atp));
             qohMap.put(productId, new Double(qoh));
+            mktgPkgAtpMap.put(productId, new Double(mktgPkgAtp));
+            mktgPkgQohMap.put(productId, new Double(mktgPkgQoh));
         }
+
+        results.put("availableToPromiseMap", atpMap);
+        results.put("quantityOnHandMap", qohMap);
+        results.put("mktgPkgATPMap", mktgPkgAtpMap);
+        results.put("mktgPkgQOHMap", mktgPkgQohMap);
         return results;
     }
 }