This is an automated email from the ASF dual-hosted git repository.

golja pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit f8f7949738f2bdc76ff3b6be60871dfd026b25f8
Author: Anahita Goljahani <[email protected]>
AuthorDate: Wed Jun 3 11:40:44 2026 +0200

    Improved: Refactor getReceiveQuantityForOrderItem and add checks for null 
quantities
    
    Thanks to Nicolas Malin for the advice and the code snippet.
---
 .../ofbiz/product/shipment/ShipmentReceiptServices.groovy    | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git 
a/applications/product/src/main/groovy/org/apache/ofbiz/product/shipment/ShipmentReceiptServices.groovy
 
b/applications/product/src/main/groovy/org/apache/ofbiz/product/shipment/ShipmentReceiptServices.groovy
index 71f795166e..c52882fae1 100644
--- 
a/applications/product/src/main/groovy/org/apache/ofbiz/product/shipment/ShipmentReceiptServices.groovy
+++ 
b/applications/product/src/main/groovy/org/apache/ofbiz/product/shipment/ShipmentReceiptServices.groovy
@@ -295,13 +295,11 @@ Map quickReceiveReturn() {
  * Computes the till now received quantity from all ShipmentReceipts
  */
 BigDecimal getReceivedQuantityForOrderItem (GenericValue orderItem) {
-    BigDecimal receivedQuantity = 0
-    List shipmentReceipts = from('ShipmentReceipt').where(orderId: 
orderItem.orderId, orderItemSeqId: orderItem.orderItemSeqId).queryList()
-    for (GenericValue shipmentReceipt : shipmentReceipts) {
-        receivedQuantity +=  shipmentReceipt.quantityAccepted
-        receivedQuantity +=  shipmentReceipt.quantityRejected
-    }
-    return receivedQuantity
+    return from('ShipmentReceipt')
+            .where(orderId: orderItem.orderId,
+                    orderItemSeqId: orderItem.orderItemSeqId)
+            .queryList()
+            .sum { (it.quantityAccepted ?: 0) + (it.quantityRejected ?: 0) }
 }
 
 /**

Reply via email to