svn commit: r600629 - in /ofbiz/trunk/applications/order: entitydef/eecas.xml servicedef/secas.xml servicedef/services_requirement.xml src/org/ofbiz/order/requirement/RequirementServices.java

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

svn commit: r600629 - in /ofbiz/trunk/applications/order: entitydef/eecas.xml servicedef/secas.xml servicedef/services_requirement.xml src/org/ofbiz/order/requirement/RequirementServices.java

sichen
Author: sichen
Date: Mon Dec  3 10:45:37 2007
New Revision: 600629

URL: http://svn.apache.org/viewvc?rev=600629&view=rev
Log:
Instead of using an EECA to create auto order requirements, do it when order status changes from created to approved.

Modified:
    ofbiz/trunk/applications/order/entitydef/eecas.xml
    ofbiz/trunk/applications/order/servicedef/secas.xml
    ofbiz/trunk/applications/order/servicedef/services_requirement.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java

Modified: ofbiz/trunk/applications/order/entitydef/eecas.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/eecas.xml?rev=600629&r1=600628&r2=600629&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/entitydef/eecas.xml (original)
+++ ofbiz/trunk/applications/order/entitydef/eecas.xml Mon Dec  3 10:45:37 2007
@@ -34,9 +34,6 @@
         <action service="quickReceiveReturn" mode="sync"/>
     </eca>
     
-    <eca entity="OrderItem" operation="create" event="return">
-        <action service="checkCreateOrderRequirement" mode="sync"/>
-    </eca>
     <eca entity="OrderItem" operation="create-store" event="return">
         <condition field-name="quoteId" operator="is-not-empty"/>
         <action service="checkUpdateQuoteStatus" mode="sync"/>

Modified: ofbiz/trunk/applications/order/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=600629&r1=600628&r2=600629&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/secas.xml Mon Dec  3 10:45:37 2007
@@ -285,6 +285,14 @@
         <action service="createRequirementFromItemATP" mode="sync" run-as-user="system"/>
         <action service="checkCreateStockRequirementAtp" mode="sync" run-as-user="system"/>
     </eca>
+    <!-- create the automatic requirements for sales orders but only if the status changes from created to approved -->
+    <eca service="changeOrderStatus" event="commit" run-on-error="false">
+        <condition field-name="oldStatusId" operator="equals" value="ORDER_CREATED"/>
+        <condition field-name="statusId" operator="equals" value="ORDER_APPROVED"/>
+        <condition field-name="orderTypeId" operator="equals" value="SALES_ORDER"/>
+        <action service="createAutoRequirementsForOrder" mode="sync"/>
+    </eca>
+
     <!-- WorkEffort -->
     <eca service="createQuoteWorkEffort" event="invoke">
         <condition field-name="workEffortId" operator="is-empty" />

Modified: ofbiz/trunk/applications/order/servicedef/services_requirement.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_requirement.xml?rev=600629&r1=600628&r2=600629&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_requirement.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_requirement.xml Mon Dec  3 10:45:37 2007
@@ -178,5 +178,13 @@
         <attribute mode="IN" name="fromFacilityId" optional="false" type="String"/>
         <attribute mode="IN" name="quantity" optional="true" type="Double"/>
     </service>
+
+    <service name="createAutoRequirementsForOrder" engine="java"
+            location="org.ofbiz.order.requirement.RequirementServices" invoke="createAutoRequirementsForOrder" auth="true">
+        <description>
+            Creates requirements for any products with requirementMethodEnumId PRODRQM_AUTO in the given sales order.
+        </description>
+        <attribute name="orderId" type="String" mode="IN" optional="false"/>
+    </service>
 </services>
 

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java?rev=600629&r1=600628&r2=600629&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java Mon Dec  3 10:45:37 2007
@@ -44,7 +44,7 @@
     public static final String module = RequirementServices.class.getName();
     public static final String resource_error = "OrderErrorUiLabels";
 
-    public static final Map getRequirementsForSupplier(DispatchContext ctx, Map context) {
+    public static Map getRequirementsForSupplier(DispatchContext ctx, Map context) {
         GenericDelegator delegator = ctx.getDelegator();
         LocalDispatcher dispatcher = ctx.getDispatcher();
         Locale locale = (Locale) context.get("locale");
@@ -192,4 +192,45 @@
             return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderEntityExceptionSeeLogs", locale));
         }
     }
+
+    // note that this service is designed to work only when a sales order status changes from CREATED -> APPROVED because HOLD -> APPROVED is too complex
+    public static Map createAutoRequirementsForOrder(DispatchContext ctx, Map context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+
+        String orderId = (String) context.get("orderId");
+        try {
+            GenericValue order = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
+            GenericValue productStore = order.getRelatedOneCache("ProductStore");
+            String facilityId = productStore.getString("inventoryFacilityId");
+            List orderItems = order.getRelated("OrderItem");
+            for (Iterator iter = orderItems.iterator(); iter.hasNext(); ) {
+                GenericValue item = (GenericValue) iter.next();
+                GenericValue product = item.getRelatedOne("Product");
+                if (product == null) continue;
+                if (! "PRODRQM_AUTO".equals(product.get("requirementMethodEnumId"))) continue;
+
+                Double quantity = item.getDouble("quantity");
+                Double cancelQuantity = item.getDouble("cancelQuantity");
+                Double required = new Double( quantity.doubleValue() - (cancelQuantity == null ? 0.0 : cancelQuantity.doubleValue()) );
+                if (required.doubleValue() <= 0.0) continue;
+
+                Map input = UtilMisc.toMap("userLogin", userLogin, "facilityId", facilityId, "productId", product.get("productId"), "quantity", required, "requirementTypeId", "PRODUCT_REQUIREMENT");
+                Map results = dispatcher.runSync("createRequirement", input);
+                if (ServiceUtil.isError(results)) return results;
+                String requirementId = (String) results.get("requirementId");
+
+                input = UtilMisc.toMap("userLogin", userLogin, "orderId", order.get("orderId"), "orderItemSeqId", item.get("orderItemSeqId"), "requirementId", requirementId, "quantity", required);
+                results = dispatcher.runSync("createOrderRequirementCommitment", input);
+                if (ServiceUtil.isError(results)) return results;
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+        } catch (GenericServiceException e) {
+            Debug.logError(e, module);
+        }
+        return ServiceUtil.returnSuccess();
+    }
 }
+