svn commit: r442140 - in /incubator/ofbiz/trunk/applications/order: servicedef/secas.xml servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

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

svn commit: r442140 - in /incubator/ofbiz/trunk/applications/order: servicedef/secas.xml servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

jacopoc
Author: jacopoc
Date: Mon Sep 11 02:40:49 2006
New Revision: 442140

URL: http://svn.apache.org/viewvc?view=rev&rev=442140
Log:
Automatic creation of a purchase order from the 'drop ship' shipment group;
the ship to address in the po is the one set in the sales order 'drop ship' shipment group.

Modified:
    incubator/ofbiz/trunk/applications/order/servicedef/secas.xml
    incubator/ofbiz/trunk/applications/order/servicedef/services.xml
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: incubator/ofbiz/trunk/applications/order/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/servicedef/secas.xml?view=diff&rev=442140&r1=442139&r2=442140
==============================================================================
--- incubator/ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ incubator/ofbiz/trunk/applications/order/servicedef/secas.xml Mon Sep 11 02:40:49 2006
@@ -23,6 +23,10 @@
         <action service="resetGrandTotal" mode="sync"/>
         <action service="addSuggestionsToShoppingList" mode="async" persist="true"/>
     </eca>
+    <eca service="storeOrder" event="return">
+        <condition field-name="orderTypeId" operator="equals" value="SALES_ORDER"/>
+        <action service="checkCreateDropShipPurchaseOrders" mode="sync"/>
+    </eca>
     <eca service="changeOrderItemStatus" event="commit">
         <condition field-name="statusId" operator="equals" value="ITEM_CANCELLED"/>
         <action service="cancelOrderInventoryReservation" mode="sync"/>

Modified: incubator/ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/servicedef/services.xml?view=diff&rev=442140&r1=442139&r2=442140
==============================================================================
--- incubator/ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ incubator/ofbiz/trunk/applications/order/servicedef/services.xml Mon Sep 11 02:40:49 2006
@@ -546,5 +546,10 @@
         <description>Remove an Order Term</description>
         <auto-attributes entity-name="OrderTerm" include="pk" mode="IN" optional="false"/>
     </service>
-</services>
 
+    <service name="checkCreateDropShipPurchaseOrders" engine="java"
+            location="org.ofbiz.order.order.OrderServices" invoke="checkCreateDropShipPurchaseOrders" auth="true">
+        <description>If the order is a sales order, create purchase orders (drop shipments) for each ship group associated to a supplier</description>
+        <attribute name="orderId" type="String" mode="IN" optional="false"/>
+    </service>
+</services>

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?view=diff&rev=442140&r1=442139&r2=442140
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Mon Sep 11 02:40:49 2006
@@ -3524,4 +3524,71 @@
 
         return ServiceUtil.returnSuccess();
     }
+
+    public static Map checkCreateDropShipPurchaseOrders(DispatchContext ctx, Map context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        // TODO (use the "system" user)
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        Locale locale = (Locale) context.get("locale");
+
+        String orderId = (String) context.get("orderId");
+        OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
+        // TODO: skip this if there is already a purchase order associated with the sales order (ship group)
+
+        try {
+            // if sales order
+            if ("SALES_ORDER".equals(orh.getOrderTypeId())) {
+                // get the order's ship groups
+                Iterator shipGroups = orh.getOrderItemShipGroups().iterator();
+                while (shipGroups.hasNext()) {
+                    GenericValue shipGroup = (GenericValue)shipGroups.next();
+                    if (!UtilValidate.isEmpty(shipGroup.getString("supplierPartyId"))) {
+                        // This ship group is a drop shipment: we create a purchase order for it
+                        String supplierPartyId = shipGroup.getString("supplierPartyId");
+                        // create the cart
+                        ShoppingCart cart = new ShoppingCart(delegator, orh.getProductStoreId(), null, orh.getCurrency());
+                        cart.setOrderType("PURCHASE_ORDER");
+                        cart.setBillToCustomerPartyId(cart.getBillFromVendorPartyId()); //Company
+                        cart.setBillFromVendorPartyId(supplierPartyId);
+                        cart.setOrderPartyId(supplierPartyId);
+                        // Get the items associated to it and create po
+                        Iterator items = orh.getValidOrderItems(shipGroup.getString("shipGroupSeqId")).iterator();
+                        while (items.hasNext()) {
+                            GenericValue item = (GenericValue)items.next();
+                            try {
+                            cart.addOrIncreaseItem(item.getString("productId"),
+                                                   null, // amount
+                                                   item.getDouble("quantity").doubleValue(),
+                                                   null, null, null, // reserv
+                                                   item.getTimestamp("shipBeforeDate"),
+                                                   item.getTimestamp("shipAfterDate"),
+                                                   null, null, null,
+                                                   null, null, null,
+                                                   dispatcher);
+                            } catch(Exception e) {
+                                ServiceUtil.returnError("The following error occurred creating drop shipments for order [" + orderId + "]: " + e.getMessage());
+                            }
+                        }
+                        // set checkout options
+                        cart.setDefaultCheckoutOptions(dispatcher);
+                        // the shipping address is the one of the customer
+                        cart.setShippingContactMechId(shipGroup.getString("contactMechId"));
+                        // create the order
+                        CheckOutHelper coh = new CheckOutHelper(dispatcher, delegator, cart);
+                        Map resultOrderMap = coh.createOrder(userLogin);
+                        String purchaseOrderId = (String)resultOrderMap.get("orderId");
+
+                        // TODO: associate the new purchase order with the sales order (ship group)
+                    }
+                }
+            }
+        } catch(Exception exc) {
+            // TODO: imporve error handling
+            ServiceUtil.returnError("The following error occurred creating drop shipments for order [" + orderId + "]: " + exc.getMessage());
+        }
+        
+        return ServiceUtil.returnSuccess();
+    }
+
 }