Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement shipment total check in brokering service for order shipgroups #51

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/OrderRoutingSeedData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<moqui.basic.Enumeration enumId="IIP_MSMNT_SYSTEM" description="Systems of measurement" sequenceNum="5" enumTypeId="INV_FILTER_PRM_TYPE" enumCode="measurementSystem"/>
<moqui.basic.Enumeration enumId="IIP_SPLIT_ITEM_GROUP" description="Split order item group" sequenceNum="6" enumTypeId="INV_FILTER_PRM_TYPE" enumCode="splitOrderItemGroup"/>
<moqui.basic.Enumeration enumId="IFP_IGNORE_ORD_FAC_LIMIT" description="Turn off the Facility order limit check" sequenceNum="7" enumTypeId="INV_FILTER_PRM_TYPE" enumCode="ignoreFacilityOrderLimit"/>
<moqui.basic.Enumeration enumId="IFP_SHIP_THREHOLD" description="Shipment threshold check" sequenceNum="8" enumTypeId="INV_FILTER_PRM_TYPE" enumCode="shipmentThreshold"/>

<moqui.basic.EnumerationType enumTypeId="ORD_SORT_PARAM_TYPE" description="Determine the order by parameter considered in a condition" parentTypeId="ORDER_ROUTING"/>
<moqui.basic.Enumeration enumId="OSP_SHIP_BY" description="Ship by" sequenceNum="5" enumTypeId="ORD_SORT_PARAM_TYPE" enumCode="shipBeforeDate"/><!-- OrderItem.shipBeforeDate -->
Expand Down
69 changes: 67 additions & 2 deletions service/co/hotwax/order/routing/OrderRoutingServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,12 @@
.requireNewTransaction(true)
.call()
if (!ec.message.hasError()) {
shipmentThresholds = ec.entity.find("co.hotwax.order.routing.OrderRoutingRuleInvCond")
.condition(["routingRuleId": routingRule.routingRuleId, "fieldName": "shipmentThreshold"]).list()
shipmentThreshold = shipmentThresholds[0]?.fieldValue
actionResult = ec.service.sync().name("co.hotwax.order.routing.OrderRoutingServices.eval#OrderRoutingActions")
.parameters([orderId: nextValue.orderId, shipGroupSeqId: nextValue.shipGroupSeqId,orderItemSeqId: orderItemSeqId, changeReasonEnumId: changeReasonEnumId,
routingRuleId: routingRule.routingRuleId, suggestedFulfillmentLocations: ruleResult.suggestedFulfillmentLocations, routingRunId: routingRunId])
routingRuleId: routingRule.routingRuleId, suggestedFulfillmentLocations: ruleResult.suggestedFulfillmentLocations, routingRunId: routingRunId, shipmentThreshold: shipmentThreshold])
.requireNewTransaction(true)
.call()
if (ec.message.hasError()) {
Expand Down Expand Up @@ -452,6 +455,7 @@
<parameter name="orderItemSeqId"/>
<parameter name="changeReasonEnumId"/>
<parameter name="routingRunId"/>
<parameter name="shipmentThreshold" type="BigDecimal"/>
<parameter name="routingRuleId" required="true"/>
<parameter name="suggestedFulfillmentLocations" type="List"/>
</in-parameters>
Expand Down Expand Up @@ -504,26 +508,64 @@
}
}
//prepare map for brokered items
def queue = null, autoCancelDate = null, brokeredItemsSeqIds = [] ;
def queue = null, autoCancelDate = null, brokeredItemsSeqIds = [], metShipmentThreshold = true;
if (suggestedFulfillmentLocations) {
brokeredItemCount = suggestedFulfillmentLocations.size();
brokeredItemsSeqIds = suggestedFulfillmentLocations.orderItemSeqId;
def checkShipmentThreshold = false;
def unfillableItems = orderItems.stream().filter(i -> !brokeredItemsSeqIds.contains(i.orderItemSeqId)).collect(Collectors.toList())
if (shipmentThreshold > 0 && !(suggestedFacilityIds.size() == 1 && !unfillableItems)) {
checkShipmentThreshold = true
}
if (checkShipmentThreshold) {
def orderAdjustments = ec.entity.find("org.apache.ofbiz.order.order.OrderAdjustment")
.condition("orderId", orderId)
.condition("orderItemSeqId", EntityCondition.NOT_EQUAL, "_NA_").list();
if (unfillableItems) {
def result = ec.service.sync().name("co.hotwax.order.routing.OrderRoutingServices.calculate#ItemSubtotal")
.parameters([orderItems: unfillableItems, orderAdjustments: orderAdjustments]).call()
if (shipmentThreshold > result?.subTotal) {
metShipmentThreshold = false;
}
}
}
if (metShipmentThreshold) {
brokeredItemCount = suggestedFulfillmentLocations.size();
suggestedFacilityIds.each { facilityId->
def facilityItems = suggestedFulfillmentLocations.collect()
filterMapList(facilityItems, ["facilityId":facilityId], false)
def items = facilityItems.collect { [orderItemSeqId: it.orderItemSeqId] }
if (checkShipmentThreshold) {
def brokeredItems = orderItems.stream().filter(i -> (items.orderItemSeqId).contains(i.orderItemSeqId)).collect(Collectors.toList())
result = ec.service.sync().name("co.hotwax.order.routing.OrderRoutingServices.calculate#ItemSubtotal")
.parameters([orderItems: brokeredItems, orderAdjustments: orderAdjustments]) .call()
if (shipmentThreshold > result?.subTotal) {
metShipmentThreshold = false;
}
}
facilityAllocation.add([facilityId:facilityId, items: items, comments: comments, routingRule: routingRuleName, changeReasonEnumId: changeReasonEnumId?:"BROKERED",
routingGroupId: orderRoutingGroup.routingGroupId, orderRoutingId:orderRouting.orderRoutingId, routingRuleId:routingRule.routingRuleId,
routingRunId: routingRunId])
}
}
if (!metShipmentThreshold) {
comments = "${orderRoutingGroup.groupName} : Shipment threshold not met for rule ${routingRule.ruleName}."
ec.logger.info("Shipment threshold condition not met for rule ${routingRule.ruleName} [${routingRule.routingRuleId}] for orderId ${orderId} and shipGroupSeqId ${shipGroupSeqId} and metShipmentThreshold ${metShipmentThreshold}");
facilityAllocation = []
brokeredItemsSeqIds = [];
brokeredItemCount = 0;
}
}

def unfillableItemSeqIds = orderItems.orderItemSeqId.stream().filter(i -> !brokeredItemsSeqIds.contains(i)).collect(Collectors.toList())
if (unfillableItemSeqIds) {
if (!comments) {
if (!suggestedFulfillmentLocations) {
comments = "${orderRoutingGroup.groupName}: No inventory found for ${routingRule.ruleName}."
} else {
comments = "${orderRoutingGroup.groupName}: Partially available item inventory found for ${routingRule.ruleName}."
}
}
// If unfillable items are found, check for actions.
if (actionMap.get('ORA_MV_TO_QUEUE') != null) {
queue = actionMap.get('ORA_MV_TO_QUEUE');
Expand Down Expand Up @@ -900,4 +942,27 @@
]]></script>
</actions>
</service>
<service verb="calculate" noun="ItemSubtotal">
<in-parameters>
<parameter name="orderItems" type="List" required="true"/>
<parameter name="orderAdjustments" type="List"/>
</in-parameters>
<out-parameters>
<parameter name="subTotal"/>
</out-parameters>
<actions>
<set field="subTotal" value="0" type="BigDecimal"/>
<iterate list="orderItems" entry="orderItem">
<set field="itemAmount" from="orderItem.quantity * orderItem.unitPrice" type="BigDecimal"/>
<filter-map-list list="orderAdjustments" to-list="itemAdjustments">
<field-map field-name="orderItemSeqId" from="orderItem.orderItemSeqId"/>
</filter-map-list>
<script>
def adjAmount = orderAdjustments?orderAdjustments.collect { adj -> adj.amount ?: 0 }.sum(): 0.0;
</script>
<set field="subTotal" from="subTotal+ itemAmount + adjAmount"/>
</iterate>
</actions>

</service>
</services>