Adding new Order state to reflect partial completion

Please help because there seems to be something I’m missing when modifying state transitions.

I’ve added a new state “Partially Completed” this should reflect the fact that some items in an order have been “Delivered”. The complication is that we do not know how many deliveries we have ahead of time.

Here is the scenario:

  1. Order is placed for 2 items, and the order gets a default delivery record for all OrderRows
  2. ItemA is delivered, add a new Delivery to the Order and set OrderRow.DeliveryId to the new Delivery.ID
  3. ItemB is delivered, add a new Delivery to the Order and set OrderRow.DeliveryId to the new Delivery.ID
  4. Both items have been delivered (and hence does not have related OrderRows anymore), so the original delivery gets set to Delivered

I’ve modified both the OrderStateBuilder to allow transition to PartiallyCompleted when not all Deliveries are in State Delivered; Completed when ALL Deliveries are in state Delivered
I’ve also added a related state to the DeliveryStateMachine to include a DeliveryState.Delivered to an OrderState.PartiallyDelivered (in addition to the previously existing related state DeliveryState to OrderState.Completed).

When running the OrderStateBuilder is invoked when the first Delivery is made (ItemA) but no longer after that (delivering ItemB cause no changes in the state machine).

I should additionally point out that after adding the related state for PartiallyCompleted, the second Delivery state does not actually change when I call SetDeliveryStatus

Any tips? Anything else I should be thinking about?

Regards, Stephen

Litium version: 5.6.8

May I know, why you need a “Partially delivered” state to be added to the order in the first place please?

  • Do you have any events that fire when a order becomes partially delivered?
  • Do you have any constraints to move in or move out from a partially delivered order?
  • Are there any integration related constraints, that you would want to filter out orders in partially completed state?

Or, is it purely a visual thing in the back-office?

Hello Anusha,

  • We need to send notifications for deliveries and to ensure that an intermediate state can be used to treat the order as not completed but passed the initial “Processing” state
  • In the OrderStateMachine I’ve defined a transition for
    (A) Processing → ParitallyCompleted when ANY delivery is set to DeliveryState.Delivered; and
    (B) PartiallyCompleted → Completed when ALL deliveries are set to DeliveryState.Delivered

We want to do this for purely functional reasons. The external client needs to be notified of order confirmation, each individual delivery and ultimately completion.

I just found my issue :man_facepalming:

As it turns out, there was a constraint on transitioning a Delivery from DeliveryState.Init to DeliveryState.Processing where the OrderState had to have OrderState.Processing.

This is of course not the case with my scenario as the Order has transitioned from OrderState.Processing to OrderState.PartiallyCompleted.

Adding OrderState.PartiallyCompleted to this Delivery constraint solved my problem!

Note to self, analyze ALL state transitions to understand how the 2 engines interact with each other.

Thanks for attention to this issue.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.