This is an automated email from the ASF dual-hosted git repository.
mridulpathak 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 1c7d6949b1 Fixed: createOrderShipmentPlan leaks order items across
ship groups (OFBIZ-13520)
1c7d6949b1 is described below
commit 1c7d6949b10adbcaafc55bf2828987fde5ac0b60
Author: Mridul Pathak <[email protected]>
AuthorDate: Thu Sep 3 18:30:36 2026 +0530
Fixed: createOrderShipmentPlan leaks order items across ship groups
(OFBIZ-13520)
createOrderShipmentPlan iterated every order item for each ship group
instead of only the items associated with that ship group, so a
multi-ship-group order got every item planned onto every shipment, tagged with
a ship group it did not belong to. Scope the inner loop to
OrderItemAndShipGroupAssoc records for the current ship group, use the assoc
quantity instead of the order item's total quantity, and skip a ship group
entirely when it has no associated items.
---
.../ofbiz/product/shipment/ShipmentServices.groovy | 23 +++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git
a/applications/product/src/main/groovy/org/apache/ofbiz/product/shipment/ShipmentServices.groovy
b/applications/product/src/main/groovy/org/apache/ofbiz/product/shipment/ShipmentServices.groovy
index 6e57bf6cc5..fd3eba041f 100644
---
a/applications/product/src/main/groovy/org/apache/ofbiz/product/shipment/ShipmentServices.groovy
+++
b/applications/product/src/main/groovy/org/apache/ofbiz/product/shipment/ShipmentServices.groovy
@@ -1072,16 +1072,29 @@ Map createOrderShipmentPlan () {
// get the product store entity
GenericValue productStore = from('ProductStore').where(productStoreId:
orderHeader.productStoreId).cache().queryOne()
List orderItemShipGroupList = orderHeader.getRelated('OrderItemShipGroup',
null, null, false)
+ // group OrderItemAndShipGroupAssoc records by shipGroupSeqId so that each
shipment only gets
+ // the items actually associated with its own ship group, instead of every
item on the order
+ List orderItemAndShipGroupAssocList = from('OrderItemAndShipGroupAssoc')
+ .where(orderId: orderHeader.orderId)
+ .queryList()
+ Map orderItemListByShGrpMap = [:]
+ for (GenericValue orderItemAndShipGroupAssoc :
orderItemAndShipGroupAssocList) {
+
orderItemListByShGrpMap.computeIfAbsent(orderItemAndShipGroupAssoc.shipGroupSeqId)
{ [] } << orderItemAndShipGroupAssoc
+ }
for (GenericValue orderItemShipGroup : orderItemShipGroupList) {
+ List perShipGroupItemList =
orderItemListByShGrpMap[orderItemShipGroup.shipGroupSeqId] ?: []
+ // make sure we have something to ship for this ship group; if not,
skip to the next one
+ if (!perShipGroupItemList) {
+ continue
+ }
Map serviceResult = run service: 'createShipment', with:
[primaryOrderId: orderHeader.orderId,
primaryShipGroupSeqId: orderItemShipGroup.shipGroupSeqId,
statusId:
'SHIPMENT_INPUT',
originFacilityId: productStore.inventoryFacilityId]
parameters.shipmentId = serviceResult.shipmentId
GenericValue shipment = from('Shipment').where(parameters).queryOne()
- List orderItems = orderHeader.getRelated('OrderItem', null, null,
false)
- orderItems.each { GenericValue orderItem ->
- GenericValue itemProduct = from('Product').where(productId:
orderItem.productId).cache().queryOne()
+ perShipGroupItemList.each { GenericValue orderItemAndShipGroupAssoc ->
+ GenericValue itemProduct = from('Product').where(productId:
orderItemAndShipGroupAssoc.productId).cache().queryOne()
// make sure the OrderItem is for a Product that has a ProductType
with isPhysical=Y
if (itemProduct) {
@@ -1089,10 +1102,10 @@ Map createOrderShipmentPlan () {
if (itemProductType.isPhysical == 'Y') {
// Create shipment item
run service: 'addOrderShipmentToShipment', with: [orderId:
orderHeader.orderId,
-
orderItemSeqId: orderItem.orderItemSeqId,
+
orderItemSeqId: orderItemAndShipGroupAssoc.orderItemSeqId,
shipmentId: shipment.shipmentId,
shipGroupSeqId: orderItemShipGroup.shipGroupSeqId,
-
quantity: orderItem.quantity]
+
quantity: orderItemAndShipGroupAssoc.quantity]
}
}
}