Make Order Ready Example
Make Order Ready Example
Placed orders are often placed in a "Shopping Cart" state (
order.is_ready == false), where they do not affect Customer balance and Product quantities. Later, the end user might "check out" and make the order ready. This triggers a number of logic functions described on this page.
The following table contrasts the Not Ready and Ready states of an order:
Order Not Ready
No effect. The balance is not adjusted until you check out and make the order ready.
The balance is adjusted by Orders
No effect. The inventory remains in stock and the reorder is not triggered.
total_quantity_orderedfor each ordered product Compute
In this article:
Requirements:Adjust Balance and Product Quantities
The following table summarizes Make Ready:
In the example
Make Order Ready
Adjust customer balance when order.is_ready=true
Adjust product total_qty_ordered when order.is_ready=true
iff (onHand - qtyOrdered) < reorderQty
The challenge is that Product is not directly related to Orders, so, while Product wants to sum LineItem quantities, it cannot directly reference the Order
API Creator solves this transaction by declaring the following logic:
Since the Customer has a sum:
Derive customers.balance as sum(ordersList.amount_un_paid) where is_ready = true
The Balance is increased due to the qualification condition change (
is_ready) now being met. You can define the following logic using
LineItems.isReady Lineitems.is_readyformula is a parent reference, so changes are forward chain altered parent references to children to each Lineitem. This formula activates line item logic, where the change to the qualification condition adjusts the
Product.totalQtyOrdered. The line item logic activates product logic, which computes
For more information:
The following image shows the relevant domain objects. The numbered arrows reflect the logic flow, described in the log and operation.
How to Run
- In Data Explorer, select the Customers table and the first Customer (Alpha and Sons).
- From the Orders tab, select the first order and clickZoom.
- Set theIs Readyto true, and then clickSave.
- Observe this fails with a credit limit check.
- Reselect the first customer and increase their Credit Limit to 51, and clickSave.
- Repeat steps 1 and 2.
- Observe now succeeds.
- Define one or more rules that solve the identified behavior, Check Credit. The logic triggered by each LineItems insertion is summarized as follows:
Which chains to
1 - Adjust Sum
Validation checkCredit (not shown)
2 - Cascade parent reference
3 - Adjust sum
4 - Formula
Products.total_quantity_ordered, Products.on_hand, Products.reorder_quantity
For more information about forward chaining and parent adjustment, see Logic Execution.
Observe this processing flow in the log.
This example illustrates both kinds of multi-table forward chaining:
- Parent adjustment from Orders to the customer balance.
- Child cascade from Orderis_readyto LineItems.
The credit check illustrates the most common business logic pattern: Constraining a derived result. It also illustrates the replicate junction pattern, wherein the Product sum references the Orders
is_ready, by way of the Orders table.