From a2d99d0430966ceed2cb003c96f2b9ad26b604ca Mon Sep 17 00:00:00 2001 From: Divesh Dutta Date: Sun, 19 Jun 2016 00:46:55 +0000 Subject: [PATCH] [OFBIZ-7190] Now CSR should be able to cancel order items of multiple ship groups. Also CSR should be able to cancel quantities less than ordered quantity. This should also fix OFBIZ-7255. Thanks Ankush Upadhyay for your patch. Thanks Mohammad Kathawala and Ratnesh Upadhyay for reporting the issues. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1749111 13f79535-47bb-0310-9956-ffa450edef68 --- applications/order/servicedef/services.xml | 1 + .../org/ofbiz/order/order/OrderEvents.java | 29 +++++++++---------- .../org/ofbiz/order/order/OrderServices.java | 22 ++++++++++---- .../order/template/order/EditOrderItems.ftl | 2 +- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/applications/order/servicedef/services.xml b/applications/order/servicedef/services.xml index d12d1f32c5..e519eacc77 100644 --- a/applications/order/servicedef/services.xml +++ b/applications/order/servicedef/services.xml @@ -282,6 +282,7 @@ under the License. + diff --git a/applications/order/src/org/ofbiz/order/order/OrderEvents.java b/applications/order/src/org/ofbiz/order/order/OrderEvents.java index 5c04889caf..fa91772758 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderEvents.java +++ b/applications/order/src/org/ofbiz/order/order/OrderEvents.java @@ -34,6 +34,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.io.IOUtils; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.content.data.DataResourceWorker; import org.ofbiz.entity.Delegator; @@ -43,6 +44,7 @@ import org.ofbiz.entity.util.EntityQuery; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; +import java.math.BigDecimal; /** * Order Events @@ -112,21 +114,21 @@ public class OrderEvents { Map resultMap = new HashMap(); String orderId = request.getParameter("orderId"); - String[] orderItemSeqIds = request.getParameterValues("selectedItem"); - - if (orderItemSeqIds != null) { - for (String orderItemSeqId : orderItemSeqIds) { - try { - GenericValue orderItem = EntityQuery.use(delegator).from("OrderItem").where("orderId", orderId, "orderItemSeqId", orderItemSeqId).queryOne(); - List orderItemShipGroupAssocs = orderItem.getRelated("OrderItemShipGroupAssoc", null, null, false); - for (GenericValue orderItemShipGroupAssoc : orderItemShipGroupAssocs) { - GenericValue orderItemShipGroup = orderItemShipGroupAssoc.getRelatedOne("OrderItemShipGroup", false); - String shipGroupSeqId = orderItemShipGroup.getString("shipGroupSeqId"); - + String[] selectedItems = request.getParameterValues("selectedItem"); + + + + if (selectedItems != null) { + for (String selectedItem : selectedItems) { + String [] orderItemSeqIdAndOrderItemShipGrpId = selectedItem.split(":"); + String orderItemSeqId = orderItemSeqIdAndOrderItemShipGrpId[0]; + String shipGroupSeqId = orderItemSeqIdAndOrderItemShipGrpId[1]; + BigDecimal cancelQuantity = new BigDecimal(request.getParameter("iqm_"+orderItemSeqId+":"+shipGroupSeqId)); Map contextMap = new HashMap(); contextMap.put("orderId", orderId); contextMap.put("orderItemSeqId", orderItemSeqId); contextMap.put("shipGroupSeqId", shipGroupSeqId); + contextMap.put("cancelQuantity", cancelQuantity); contextMap.put("userLogin", userLogin); contextMap.put("locale", locale); try { @@ -144,11 +146,6 @@ public class OrderEvents { request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; } - } - } catch (GenericEntityException e) { - Debug.logError(e, module); - return "error"; - } } return "success"; } else { diff --git a/applications/order/src/org/ofbiz/order/order/OrderServices.java b/applications/order/src/org/ofbiz/order/order/OrderServices.java index f0c921b542..b7dcb39716 100644 --- a/applications/order/src/org/ofbiz/order/order/OrderServices.java +++ b/applications/order/src/org/ofbiz/order/order/OrderServices.java @@ -2058,7 +2058,14 @@ public class OrderServices { String shipGroupSeqId = (String) context.get("shipGroupSeqId"); Map itemReasonMap = UtilGenerics.checkMap(context.get("itemReasonMap")); Map itemCommentMap = UtilGenerics.checkMap(context.get("itemCommentMap")); - + Map itemQuantityMap = UtilGenerics.checkMap(context.get("itemQtyMap")); + if ((cancelQuantity == null) && UtilValidate.isNotEmpty(itemQuantityMap)) { + String key = orderItemSeqId+":"+shipGroupSeqId; + if (UtilValidate.isNotEmpty(itemQuantityMap.get(key))) { + cancelQuantity = new BigDecimal(itemQuantityMap.get(key)); + } + + } // debugging message info String itemMsgInfo = orderId + " / " + orderItemSeqId + " / " + shipGroupSeqId; @@ -2157,12 +2164,15 @@ public class OrderServices { "orderId", orderItem.getString("orderId"), "orderItemSeqId", orderItem.getString("orderItemSeqId"), "shipGroupSeqId", orderItemShipGroupAssoc.getString("shipGroupSeqId")); - try { - dispatcher.runSync("deleteOrderItemShipGroupAssoc", localCtx); - } catch (GenericServiceException e) { - Debug.logError(e, module); - return ServiceUtil.returnError(e.getMessage()); + if (availableQuantity.compareTo(thisCancelQty) == 0) { + try { + dispatcher.runSync("deleteOrderItemShipGroupAssoc", localCtx); + } catch (GenericServiceException e) { + Debug.logError(e, module); + return ServiceUtil.returnError(e.getMessage()); + } } + // create order item change record if (!"Y".equals(orderItem.getString("isPromo"))) { diff --git a/applications/order/template/order/EditOrderItems.ftl b/applications/order/template/order/EditOrderItems.ftl index 9187f80b1d..6079c72e06 100644 --- a/applications/order/template/order/EditOrderItems.ftl +++ b/applications/order/template/order/EditOrderItems.ftl @@ -257,7 +257,7 @@ under the License. <#if itemSelectable> - +