You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by di...@apache.org on 2016/08/27 08:06:25 UTC

svn commit: r1757964 - in /ofbiz/trunk/applications/order: servicedef/ src/main/java/org/apache/ofbiz/order/requirement/ src/main/java/org/apache/ofbiz/order/shoppingcart/

Author: diveshdutta
Date: Sat Aug 27 08:06:24 2016
New Revision: 1757964

URL: http://svn.apache.org/viewvc?rev=1757964&view=rev
Log:
[OFBIZ-7478] Mark the requirements Ordered only when PO is approved. Earlier requirements were marked Ordered when PO is created. Applied slightly modifiend patch by Rahul Bhooteshwar. In this work new service:updateRequirementsToOrdered is introduced which will be triggered when PO is approved. Thanks Rahul Bhooteshwar for you patch and Swapnil Shah for reporting the ticket

Modified:
    ofbiz/trunk/applications/order/servicedef/secas.xml
    ofbiz/trunk/applications/order/servicedef/services_requirement.xml
    ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/requirement/RequirementServices.java
    ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java

Modified: ofbiz/trunk/applications/order/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/secas.xml?rev=1757964&r1=1757963&r2=1757964&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/secas.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/secas.xml Sat Aug 27 08:06:24 2016
@@ -378,6 +378,13 @@ under the License.
         <action service="createATPRequirementsForOrder" mode="sync"/>
     </eca>
 
+    <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="PURCHASE_ORDER"/>
+        <action service="updateRequirementsToOrdered" mode="sync"/>
+    </eca>
+
     <!-- WorkEffort -->
     <eca service="createQuoteWorkEffort" event="in-validate">
         <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=1757964&r1=1757963&r2=1757964&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_requirement.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_requirement.xml Sat Aug 27 08:06:24 2016
@@ -194,5 +194,12 @@ under the License.
         </description>
         <attribute name="orderId" type="String" mode="IN" optional="false"/>
     </service>
+    <service name="updateRequirementsToOrdered" engine="java"
+             location="org.apache.ofbiz.order.requirement.RequirementServices" invoke="updateRequirementsToOrdered" auth="true">
+        <description>
+            Update requirement's status to Ordered after PO is approved.
+        </description>
+        <attribute name="orderId" type="String" mode="IN" optional="false"/>
+    </service>
 </services>
 

Modified: ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/requirement/RequirementServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/requirement/RequirementServices.java?rev=1757964&r1=1757963&r2=1757964&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/requirement/RequirementServices.java (original)
+++ ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/requirement/RequirementServices.java Sat Aug 27 08:06:24 2016
@@ -29,6 +29,7 @@ import org.apache.ofbiz.entity.GenericEn
 import org.apache.ofbiz.entity.GenericValue;
 import org.apache.ofbiz.entity.util.EntityQuery;
 import org.apache.ofbiz.entity.util.EntityUtil;
+import org.apache.ofbiz.order.order.OrderReadHelper;
 import org.apache.ofbiz.service.DispatchContext;
 import org.apache.ofbiz.service.GenericServiceException;
 import org.apache.ofbiz.service.LocalDispatcher;
@@ -327,6 +328,33 @@ public class RequirementServices {
             Debug.logError(e, module);
         }
         return ServiceUtil.returnSuccess();
+    }
+
+    public static Map<String, Object> updateRequirementsToOrdered (DispatchContext ctx, Map<String, ? extends Object> context) {
+        Delegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        String orderId = (String) context.get("orderId");
+        OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
+        try {
+            for(GenericValue orderItem: orh.getOrderItems()){
+                GenericValue orderRequirementCommitment = EntityQuery.use(delegator).from("OrderRequirementCommitment")
+                        .where(UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItem.getString("orderItemSeqId")))
+                        .queryFirst();
+                if (UtilValidate.isNotEmpty(orderRequirementCommitment)) {
+                    String requirementId = orderRequirementCommitment.getString("requirementId");
+                    /* Change status of requirement to ordered */
+                    Map<String, Object> inputMap = UtilMisc.<String, Object>toMap("userLogin", userLogin, "requirementId", requirementId, "statusId", "REQ_ORDERED", "quantity", orderItem.getBigDecimal("quantity"));
+                    // TODO: check service result for an error return
+                    dispatcher.runSync("updateRequirement", inputMap);
+                }
+            }
+        } catch(GenericEntityException e){
+            Debug.logError(e, module);
+        } catch(GenericServiceException e){
+            Debug.logError(e, module);
+        }
+        return ServiceUtil.returnSuccess();
     }
 }
 

Modified: ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java?rev=1757964&r1=1757963&r2=1757964&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java (original)
+++ ofbiz/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/CheckOutHelper.java Sat Aug 27 08:06:24 2016
@@ -672,11 +672,8 @@ public class CheckOutHelper {
             String requirementId = shoppingCartItem.getRequirementId();
             if (requirementId != null) {
                 try {
-                    Map<String, Object> inputMap = UtilMisc.<String, Object>toMap("requirementId", requirementId, "statusId", "REQ_ORDERED");
-                    inputMap.put("userLogin", userLogin);
-                    // TODO: check service result for an error return
-                    dispatcher.runSync("updateRequirement", inputMap);
-                    inputMap = UtilMisc.toMap("userLogin", userLogin, "orderId", orderId, "orderItemSeqId", shoppingCartItem.getOrderItemSeqId(), "requirementId", requirementId, "quantity", shoppingCartItem.getQuantity());
+                    /* OrderRequirementCommitment records will map which POs which are created from which requirements. With the help of this mapping requirements will be updated to Ordered when POs will be approved.  */
+                    Map<String, Object> inputMap = UtilMisc.toMap("userLogin", userLogin, "orderId", orderId, "orderItemSeqId", shoppingCartItem.getOrderItemSeqId(), "requirementId", requirementId, "quantity", shoppingCartItem.getQuantity());
                     dispatcher.runSync("createOrderRequirementCommitment", inputMap);
                 } catch (Exception e) {
                     String service = e.getMessage();