[OFBiz] SVN: r6069 - in trunk/applications/product: servicedef src/org/ofbiz/shipment/shipment

sichen at svn.ofbiz.org sichen at svn.ofbiz.org
Fri Nov 4 12:00:12 EST 2005


Author: sichen
Date: 2005-11-04 11:00:04 -0600 (Fri, 04 Nov 2005)
New Revision: 6069

Modified:
   trunk/applications/product/servicedef/secas_shipment.xml
   trunk/applications/product/servicedef/services_shipment.xml
   trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java
Log:
New service to check when items are received whether they complete their purchase shipment.  Using this, a purchase shipment can be marked RECEIVED automatically when all its items are received, and an invoice can be automatically generated.

Modified: trunk/applications/product/servicedef/secas_shipment.xml
===================================================================
--- trunk/applications/product/servicedef/secas_shipment.xml	2005-11-04 16:11:21 UTC (rev 6068)
+++ trunk/applications/product/servicedef/secas_shipment.xml	2005-11-04 17:00:04 UTC (rev 6069)
@@ -88,6 +88,10 @@
         <condition field-name="orderId" operator="is-not-empty"/>
         <action service="updateOrderStatusFromReceipt" mode="sync"/>
     </eca>
+    <eca service="createShipmentReceipt" event="commit">
+        <condition field-name="shipmentId" operator="is-not-empty"/>
+        <action service="updatePurchaseShipmentFromReceipt" mode="sync"/>
+    </eca>
 
     <eca service="createShipmentPackageContent" event="in-validate">
         <condition field-name="shipmentPackageSeqId" operator="equals" value="New"/>

Modified: trunk/applications/product/servicedef/services_shipment.xml
===================================================================
--- trunk/applications/product/servicedef/services_shipment.xml	2005-11-04 16:11:21 UTC (rev 6068)
+++ trunk/applications/product/servicedef/services_shipment.xml	2005-11-04 17:00:04 UTC (rev 6069)
@@ -422,6 +422,17 @@
         <implements service="interfaceShipmentReceipt"/>
         <attribute name="receiptId" type="String" mode="OUT" optional="false"/>
     </service>
+    <service name="updatePurchaseShipmentFromReceipt" engine="java"
+      location="org.ofbiz.shipment.shipment.ShipmentServices" invoke="updatePurchaseShipmentFromReceipt" auth="true">
+        <description>
+          Whenever a ShipmentReceipt is generated, check the Shipment associated
+          with it to see if all items were received. If so, change its status to
+          PURCH_SHIP_RECEIVED. The check is accomplished by counting the 
+          products shipped (from ShipmentAndItem) and matching them with the 
+          products received (from ShipmentReceipt).
+        </description>
+        <attribute name="shipmentId" type="String" mode="IN" optional="false"/>
+    </service>
 
     <service name="prepareInventoryReceipt" engine="simple"
             location="org/ofbiz/shipment/receipt/ShipmentReceiptServices.xml" invoke="prepareInventoryReceipt" auth="true">

Modified: trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java
===================================================================
--- trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java	2005-11-04 16:11:21 UTC (rev 6068)
+++ trunk/applications/product/src/org/ofbiz/shipment/shipment/ShipmentServices.java	2005-11-04 17:00:04 UTC (rev 6069)
@@ -792,4 +792,61 @@
         }
         return ServiceUtil.returnSuccess();
     }
+
+    /**
+     * Whenever a ShipmentReceipt is generated, check the Shipment associated
+     * with it to see if all items were received. If so, change its status to
+     * PURCH_SHIP_RECEIVED. The check is accomplished by counting the 
+     * products shipped (from ShipmentAndItem) and matching them with the 
+     * products received (from ShipmentReceipt).
+     */
+    public static Map updatePurchaseShipmentFromReceipt(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        String shipmentId = (String) context.get("shipmentId");
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        try {
+            List shipmentAndItems = delegator.findByAnd("ShipmentAndItem", UtilMisc.toMap("shipmentId", shipmentId, "statusId", "PURCH_SHIP_SHIPPED"));
+            if (shipmentAndItems.size() == 0) return ServiceUtil.returnSuccess();
+            List shipmentReceipts = delegator.findByAnd("ShipmentReceipt", UtilMisc.toMap("shipmentId", shipmentId));
+            if (shipmentReceipts.size() == 0) return ServiceUtil.returnSuccess();
+
+            // store the quanitity of each product shipped in a hashmap keyed to productId
+            Map shippedCountMap = new HashMap();
+            Iterator iter = shipmentAndItems.iterator();
+            while (iter.hasNext()) {
+                GenericValue item = (GenericValue) iter.next();
+                double shippedQuantity = item.getDouble("quantity").doubleValue();
+                Double quantity = (Double) shippedCountMap.get(item.getString("productId"));
+                quantity = new Double(quantity == null ? shippedQuantity : shippedQuantity + quantity.doubleValue());
+                shippedCountMap.put(item.getString("productId"), quantity);
+            }
+
+            // store the quanitity of each product received in a hashmap keyed to productId
+            Map receivedCountMap = new HashMap();
+            iter = shipmentReceipts.iterator();
+            while (iter.hasNext()) {
+                GenericValue item = (GenericValue) iter.next();
+                double receivedQuantity = item.getDouble("quantityAccepted").doubleValue();
+                Double quantity = (Double) receivedCountMap.get(item.getString("productId"));
+                quantity = new Double(quantity == null ? receivedQuantity : receivedQuantity + quantity.doubleValue());
+                receivedCountMap.put(item.getString("productId"), quantity);
+            }
+
+            // let Map.equals do all the hard comparison work
+            if (!shippedCountMap.equals(receivedCountMap)) {
+                return ServiceUtil.returnSuccess();
+            }
+
+            // now update the shipment
+            dispatcher.runSync("updateShipment", UtilMisc.toMap("shipmentId", shipmentId, "statusId", "PURCH_SHIP_RECEIVED", "userLogin", userLogin));
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        } catch (GenericServiceException se) {
+            Debug.logError(se, module);
+            return ServiceUtil.returnError(se.getMessage());
+        }
+        return ServiceUtil.returnSuccess("Intentional error at end to keep from committing.");
+    }
 }



More information about the Svn mailing list