/
Copy of Document for "STATUS" update logic (EXPORTS)

What is the currently implemented logic?

According to the current logic, the status is getting updated as follows:

  • ACTUAL OUTCOME FROM CURRENT IMPLEMENTATION:

    1PSEUDO CODE: 2FOR reference order_items is a table in our Database 3 4Various conditions according to which the current status is updated: 51. if (order_items.status == "ONHOLD") 6 the condition is true then update the current status to ONHOLD 72. if (order_items.status=="CANCELLED") 8 the condition is true then update the current status to CANCELLED 93. if (check if return flag is true means return is created){ 10 and latestStatus is not null means it has a value then we 11 update the current status to a status from RETURN 12} 134. else case { 14 if latestStatus is not null we update the current status again to "NEW" in our case according to the logic 15}
    • Firstly it checks if the current status is “ON HOLD” and if it is true then we update the status to “ON HOLD”.

    • Secondly, if the current status is “CANCELLED” and if it is true then we again update the status so the final status after two movements is “CANCELLED”.

    • After the first two steps, we check if the return is created for the same order or not and if the return is created we check if “latestStatus” is not null means it has a value in it we update the current status again so, final status moves again to “RETURN ON THE WAY”

    • If the return is not created, we are again updating the status here which is in our case “NEW”

  • EXPECTED:

Value required for the below logic to execute

  1. order_items.onhold

  2. order_items.status

  3. order_items.returnFlag

  4. order_items.reversePickupReason

  5. order_items.warehouseInboundStatus

  6. shipment_status_logs.latestReturnStatus

  7. shipment_status_logs.latestOrderStatus

  8. shipment_status_logs.latestOrderStatusBeforeDispatched

  9. return_shipment_status_logs.latestReturnStatus

  10. orders.thirdPartyShipping

1PSEUDO CODE 2 3Order STATUS for export: 4 if (order_items.status == "CANCELLED") { 5 currentOrderStatus == "CANCELLED" 6 return currentOrderStatus; 7 } 8 if (order_items.shipment_id == 0) { 9 currentOrderStatus == "UNFULFILLABLE" 10 return currentOrderStatus; 11 } 12 if ((order_items.status == "ONHOLD" OR order_items.onhold == "1") && order_items.returnFlag == "0") { 13 currentOrderStatus == "ONHOLD" 14 return currentOrderStatus; 15 } 16 if (order_items.returnFlag == "1" AND order_items.warehouseInboundStatus == “received”) { 17 currentOrderStatus == "RETURN IN PROCESSING" 18 return currentOrderStatus; 19 } 20 if (order_items.returnFlag == "1" AND order_items.warehouseInboundStatus == “complete”) { 21 if (order_items.reversePickupReason == “good_inventory”) 22 currentOrderStatus == "RESTOCKED" 23 return currentOrderStatus; 24 if (order_items.reversePickupReason == “bad_inventory”) 25 currentOrderStatus == "QUARANTINED" 26 return currentOrderStatus; 27 if (order_items.reversePickupReason == “lost” OR order_items.reversePickupReason == “partial_lost”) 28 currentOrderStatus == "LOST IN PROCESSING" 29 return currentOrderStatus; 30 } 31 if (order_items.returnFlag == "1" AND order_items.return_shipment_id != 0) { 32 if (return shipment status log == NULL ) { 33 if (order.thirdPartyShipping == 0) { 34 currentorderStatus = Awaiting Pickup 35 } else { 36 currentorderStatus = return on the way 37 } 38 } else { 39 latestStatus (return shipment status) 40 currentOrderStatus = latestStatus 41 if (order.thirdPartyShipping == 1 AND (currentOrderStatus == "awaiting_pickup", "return_lost", "pickup_cancelled", "return_damaged")){ 42 currentOrderStatus = "Return on the way" 43 } 44 return currentOrderStatus; 45 } 46 } 47 if (order_items.returnFlag == "1" AND order_items.return_shipment_id == 0 ) { 48 if (shipmentStatusLogDto != null) { 49 latestReturnStatus (shipment status log) 50 currentOrderStatus = latestStatus 51 return currentOrderStatus; 52 } else { 53 currentOrderStatus == "UNFULFILLABLE" 54 return currentOrderStatus; 55 } 56 } 57 if (order_items.returnFlag == "0") { 58 if (shipmentStatusLogDto != null){ 59 if (statuslogs.contains("cancelled")){ 60 currentOrderStatus == "CANCELLED" 61 return currentOrderStatus; 62 } 63 if (orders.thirdPartyShipping == 0 && "dispatched" == latestForwardOrderStatus){ 64 latestStatus = latestForwardOrderStatusBeforeDispatched 65 } else { 66 latestStatus = latestForwardStatus 67 } 68 currentOrderStatus = latestStatus 69 if (order.thirdPartyShipping == 1 AND (currentOrderStatus == "on the way", "out for delivery", "delivered", "delivery cancelled", "order lost")){ 70 currentOrderStatus = "HANDOVER DONE" 71 } 72 } else { 73 currentOrderStatus == "UNFULFILLABLE" 74 return currentOrderStatus; 75 } 76 return currentOrderStatus; 77 } 78 79 80 AWAITING_PICKUP : "created", "order_placed", "pickup_pending", "approved", "out_for_pickup", 81 "pickup_cancelled", "pickup_failed" 82 RETURN_LOST : "lost", "rto_lost", "damaged", "rto_damaged" 83 PICKUP_CANCELLED : "return_cancelled", "cancelled_order", "order_cancelled", "cancelled" 84 RETURN_DAMAGED 85 86 ON THE WAY : "picked_up", "intransit", "shipment_delayed", "not_serviceable", "failed_delivery", 87 "shipment_held", "ndr_resolution_submitted" 88 OUT_FOR_DELIVERY : "out_for_delivery" 89 DELIVERED : "delivered" 90 DELIVERY_CANCELLED : "rto", "rto_created", "rto_requested", "return_expected" 91 ORDER_LOST : "lost", "damaged" 92
  • First, we will check whether order_item.status == “CANCELLED” AND returnFlag == 0, then show the current status as “CANCELLED” on export (break out of the function) cases should be made

  • Check if shipment_id == 0 AND returnFlag == 0 then set the current status as “UNFULFILLABLE” (break)

  • Now based order_item.status, check if order_item.onhold == 1 AND returnFlag == 0 set the current status to “ONHOLD” (break)

  • When order_item.returnFlag == 1 AND order_item.warehouseInboundStatus == “received” set the current status as “RETURN IN PROCESSING” and then (break)

  • When order_item.returnFlag == 1 AND order_item.warehouseInboundStatus == “complete”

    • Now check if order_item.reversePickupReason == “good_inventory” then set the current status as “RESTOCKED” and then (break)

    • Now check if order_item.reversePickupReason == “bad_inventory” then set the current status as “QUARANTINED” and then (break)

    • Now check if order_item.reversePickupReason == “lost” OR “partial_lost” then set the current status as “LOSTINPROCESSING” then (break)

  • Fetch latestStatus of return shipment status log if order_item.returnFlag == 1 AND order_item.return_shipment_id != 0, set current order status on the basis of latestStatus and then (break).

  • Fetch latest return status of shipment status log if order_item.returnFlag == 1 AND order_item.return_shipment_id == 0, set current order status on the basis latestReturnStatus and then (break)

  • Fetch latest order status of shipment status log if order_item.returnFlag == 0, set current order status on the basis of latestOrderStatus (break)

1//return shipment status logs DTO 2if (status.created) { 3 dto.setReturnCreatedDateTime(); 4} else if (status.picked_up) { 5 dto.setReturnPickedUpDateTime(); 6} else if (status.out_for_pickup) { 7 if (!isFirstOutForPickupCovered) { 8 isFirstOutForPickupCovered = true; 9 dto.setFirstOutForPickupDateTime(); 10 } 11 outForPickupAttempts++; 12 dto.setPickupAttempts(outForPickupAttempts); 13 dto.setLatestOutForPickupDateTime(); 14} else if (status.pickup_cancelled) { 15 failedPickupAttempts++; 16 dto.setFailedPickupAttempts(failedPickupAttempts); 17 dto.setFailedPickupDateTime(); 18 dto.setLatestFailedPickupRemarks(); 19 dto.setLatestFailedPickupReason(); 20} else if (status.delivered) { 21 dto.setReturnDeliveredDateTime(); 22} else if (status.received) { 23 dto.setReturnReceivedDateTime(); 24} else if (status.approved) { 25 dto.setExpectedPickupDateTime(); 26} 27dto.setLatestReturnStatus(status);
1shipmentStatusLogDTO forward shipment status logs 2 3boolean isPackedCovered = false; 4boolean isDispatchedCovered = false; 5 6if (status.created) { 7 //we set createdDateTime 8 dto.setCreatedDateTime 9 //fetch remark in next step 10 //check if pincode is serviceable if not set 11 if(remark == "pincode unserviceable") 12 dto.setonholdReason 13} else if (status.picking) { 14 dto.setPickingDateTime(); 15} else if (status.failedtoRts) { 16 if (!isRtsFirstAttemptDone) { 17 //if rtsFirstAttemptDone == true then 18 dto.setFirstRtsDateTime() 19 } 20 failedRtsAttempts++; 21 dto.setFailedRtsAttempts(failedRtsAttempts); 22 dto.setLatestRtsDateTime(); 23 //check remark 24 if (remark == "error message dummy"){ 25 //fetch details of map 26 } 27 dto.setLatestFailedToRtsReason(remark); 28 //handling if received failed_to_rts after packed 29 if(isPackedCovered) { 30 continue; 31 } 32} else if (status.picked) { 33 dto.setPickedDateTime(); 34} else if (status.packed) { 35 //case where failed_to_rts after packed 36 isPacked = true; 37 dto.setPackedDateTime(); 38} else if (status.failed_to_handover) { 39 dto.setfailedtohandoverDateTime(); 40 if(isDispatchedCovered) { 41 continue; 42 } 43} else if (status.dispatched) { 44 dto.setdispatchedDateTime(); 45 isDispatchedCovered = true; 46} else if (status.shipped) { 47 dto.setShippedDateTime(); 48} else if (status.cancelled) { 49 dto.setIsCancelled(true); 50 dto.setCancelledDateTime(); 51 if (fulfillment_cancel) { 52 dto.setCancelledBy("Seller") 53 } else { 54 dto.setCancelledBy("Customer") 55 } 56} else if (status.picked_up) { 57 dto.setPickedUpDateTime(); 58} else if (status.out_for_delivery) { 59 if (!isOutForDeliveryFirstAttemptDone) { 60 isOutForDeliveryFirstAttemptDone = true; 61 dto.setFirstOutForDeliveryDateTime(); 62 } 63 outForDeliveryAttempts++; 64 dto.setOutForDeliveryAttempts(outForDeliveryAttempts); 65 dto.setLatestOutForDeliveryDateTime(); 66 isDispatchedCovered = true; 67} else if (status.failed_delivery) { 68 if (!isFirstFailedDeliveryCovered) { 69 isFirstFailedDeliveryCovered = true; 70 dto.setFirstFailedDeliveryDateTime(); 71 } 72 failedDeliveryAttempts++; 73 dto.setDeliveryFailedAttempts(failedDeliveryAttempts); 74 dto.setLatestFailedDeliveryDateTime(); 75 dto.setLatestFailedDeliveryRemark(); 76 dto.setLatestFailedDeliveryReason("ndr_status_description"); 77} else if (status.ndr_resolution_submitted) { 78 dto.setFailedDeliveryAction(); 79} else if (status.delivered) { 80 dto.setDeliveredDateTime(); 81} else if (status.rto && status.rto_created) { 82 isRTOCovered = true; 83 dto.setReturnCreatedDateTime(); 84} else if (status.rto_received && status.received) { 85 dto.setReturnReceivedDateTime(); 86} else if (status.rto_delivered) { 87 dto.setReturnDeliveredDateTime(); 88} if (AlgoliaOrderItemEnum.isStatusByCategory(Category.RETURNS, status)) { 89 dto.setLatestReturnStatus(status); 90} 91if (AlgoliaOrderItemEnum.ON_THE_WAY.getStatusLogs().contains(status)) { 92 if (!isFirstOnTheWayCovered) { 93 isFirstOnTheWayCovered = true; 94 dto.setFirstOnTheWayDateTime(); 95 } 96 if (status.dispatched) { 97 dto.setForwardStatusBeforeDispatched(); 98 } 99 dto.setShipmentStatusLatestCreatedAt(); 100 dto.setLatestForwardOrderStatus(status); 101} 102if (dto.getDispatchedDateTime() == null)) { 103 dto.setDispatchedDateTime(shippedDateTime); 104} 105if (dto.getLatestForwardOrderStatus() != null && dto."failed_delivery")) { 106 dto.setFailedDeliveryActionStatus(); 107} else if (dto.getLatestForwardOrderStatus() != null && dto."ndr_resolution_submitted") { 108 dto.setFailedDeliveryActionStatus(); 109}