This is an automated email from the ASF dual-hosted git repository. surajk pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new fa86887 Improved: Handle case of partial amount available for return in adjustment in OrderReadHelper.getAvailableOrderHeaderAdjustments method. (OFBIZ-11185) Currently it filters all the adjustment that has correspoding returnAdjustment, it should check for amount as well. Thanks Amit Gadaley for providing the patch. fa86887 is described below commit fa86887eb6e90b73df19082236821543e90c8215 Author: Suraj Khurana <suraj.khur...@hotwax.co> AuthorDate: Sat Sep 26 17:27:50 2020 +0530 Improved: Handle case of partial amount available for return in adjustment in OrderReadHelper.getAvailableOrderHeaderAdjustments method. (OFBIZ-11185) Currently it filters all the adjustment that has correspoding returnAdjustment, it should check for amount as well. Thanks Amit Gadaley for providing the patch. --- .../org/apache/ofbiz/order/order/OrderReadHelper.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java index cdbb1bd..dc6bf73 100644 --- a/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java +++ b/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderReadHelper.java @@ -3583,21 +3583,26 @@ public class OrderReadHelper { /** * Get orderAdjustments that have no corresponding returnAdjustment + * It also handles the case of partial adjustment amount. Check OFBIZ-11185 for details * @return return the order adjustments that have no corresponding with return adjustment */ public List<GenericValue> getAvailableOrderHeaderAdjustments() { List<GenericValue> orderHeaderAdjustments = this.getOrderHeaderAdjustments(); List<GenericValue> filteredAdjustments = new LinkedList<>(); for (GenericValue orderAdjustment : orderHeaderAdjustments) { - long count = 0; + BigDecimal returnedAmount = BigDecimal.ZERO; try { - count = orderHeader.getDelegator().findCountByCondition("ReturnAdjustment", EntityCondition - .makeCondition("orderAdjustmentId", EntityOperator.EQUALS, orderAdjustment.get( - "orderAdjustmentId")), null, null); + List<GenericValue> returnAdjustments = EntityQuery.use(orderHeader.getDelegator()).from("ReturnAdjustment").where("orderAdjustmentId", orderAdjustment.getString("orderAdjustmentId")).queryList(); + if (UtilValidate.isNotEmpty(returnAdjustments)) { + for (GenericValue returnAdjustment : returnAdjustments) { + returnedAmount = returnedAmount.add(returnAdjustment.getBigDecimal("amount")); + } + } } catch (GenericEntityException e) { Debug.logError(e, MODULE); } - if (count == 0) { + if (orderAdjustment.getBigDecimal("amount").compareTo(returnedAmount) > 0) { + orderAdjustment.set("amount", orderAdjustment.getBigDecimal("amount").subtract(returnedAmount)); filteredAdjustments.add(orderAdjustment); } }