svn commit: r1757975 - in /ofbiz/branches/release14.12/applications/order: servicedef/secas.xml servicedef/services_requirement.xml src/org/ofbiz/order/requirement/RequirementServices.java src/org/ofbiz/order/shoppingcart/CheckOutHelper.java

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

svn commit: r1757975 - in /ofbiz/branches/release14.12/applications/order: servicedef/secas.xml servicedef/services_requirement.xml src/org/ofbiz/order/requirement/RequirementServices.java src/org/ofbiz/order/shoppingcart/CheckOutHelper.java

diveshdutta
Author: diveshdutta
Date: Sat Aug 27 08:54:53 2016
New Revision: 1757975

URL: http://svn.apache.org/viewvc?rev=1757975&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/branches/release14.12/applications/order/servicedef/secas.xml
    ofbiz/branches/release14.12/applications/order/servicedef/services_requirement.xml
    ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java
    ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java

Modified: ofbiz/branches/release14.12/applications/order/servicedef/secas.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/order/servicedef/secas.xml?rev=1757975&r1=1757974&r2=1757975&view=diff
==============================================================================
--- ofbiz/branches/release14.12/applications/order/servicedef/secas.xml (original)
+++ ofbiz/branches/release14.12/applications/order/servicedef/secas.xml Sat Aug 27 08:54:53 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/branches/release14.12/applications/order/servicedef/services_requirement.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/order/servicedef/services_requirement.xml?rev=1757975&r1=1757974&r2=1757975&view=diff
==============================================================================
--- ofbiz/branches/release14.12/applications/order/servicedef/services_requirement.xml (original)
+++ ofbiz/branches/release14.12/applications/order/servicedef/services_requirement.xml Sat Aug 27 08:54:53 2016
@@ -195,5 +195,12 @@ under the License.
         </description>
         <attribute name="orderId" type="String" mode="IN" optional="false"/>
     </service>
+    <service name="updateRequirementsToOrdered" engine="java"
+             location="org.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/branches/release14.12/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java?rev=1757975&r1=1757974&r2=1757975&view=diff
==============================================================================
--- ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java (original)
+++ ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java Sat Aug 27 08:54:53 2016
@@ -33,6 +33,7 @@ import org.ofbiz.entity.GenericEntityExc
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityQuery;
 import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.order.order.OrderReadHelper;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
@@ -331,6 +332,32 @@ 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 requirement's status 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/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java?rev=1757975&r1=1757974&r2=1757975&view=diff
==============================================================================
--- ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java (original)
+++ ofbiz/branches/release14.12/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutHelper.java Sat Aug 27 08:54:53 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());
+                    /*Creating OrderRequirementCommitment which will be used to update requirement at the time of approval of PO. OrderRequirementCommitment will also be updated if ordered & required quantity differs*/
+                    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();