Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

Supply

A supply entry records what arrived or is due for a resource in one scope. It carries evidence that points to your app’s record and a source key that keeps a repeated delivery from adding twice.

When supply starts

Added supply counts toward onHand. It starts immediately if validFrom is omitted or has arrived. A future validFrom starts it at that instant.

Expected supply records a quantity that is due at validFrom. It counts toward expected even after that time passes. It contributes to availability on a resource with shortage: 'backorder'. An added entry can name the expected entry it fulfils in fulfils, which reduces the quantity still due.

Draws and expiry

A resource with settings.supplyExpiry: 'expiring' keeps the remainder of each added entry separately. Each draw records how much it took from each entry in pegs. Draws use the lowest drawOrder first, counting an omitted value as 0. Among entries of the same order, the ones that expire soonest come first, and entries that never expire come last. The older entry breaks a tie. A line can name an entry with from.supplyId or a batch with from.batchId.

At expiresAt, unused units stop counting as available. When unused units remain, the expiry sweep records their removal in an expire_supply movement. A hold with pegged units keeps its draw from those entries until it resolves, so it can still commit them after the entry’s expiresAt.

Owing

With shortage: 'negative', a take that the live entries can’t cover still lands. It draws everything they have, in draw order, and owes the rest. onHand drops by the whole quantity, so it can go below zero, and the take’s movement records the amount owed in owed. Its pegs show what came off entries. What is owed belongs to no entry and never expires. A line that names an entry or batch never owes. It is refused when that source is short.

Supply that arrives while something is owed pays the owed amount first. That includes an entry whose validFrom arrives later, and units that come back from a released hold, a cancelled booking, or a settle. The entry keeps only what is left in remaining, and the movement’s owed.pegs names the entry and what it paid. Every read counts supply that has started this way, whether or not a write or sweep has landed it. A balance never owes while one of its live entries has units free.

A hold that the live entries can’t cover holds what they have and holds the rest with no entry. Its commit takes the rest from what is live then and owes what that can’t cover. A release or an expiry lets the rest go. Settling an estimate down or cancelling a booking gives back what was owed first. If supply has paid it since, those units go back to the entries that paid, starting with the most recent.

Batches

A batch groups entries for one resource with tracking: 'batch'. Batch tracking requires expiring supply. The balance and shortage rules list all the required settings. A batch has a code unique on that resource and can carry labels such as a farm or a harvest. A receipt names an existing batchId or sends a batch code to find or create the batch. Entries in a batch use the batch’s expiresAt. A balance read with by=batch shows each batch’s share at the selected scope.

Reversals

A reversal records a correction to an earlier supply entry. A take-back on a resource that keeps its supply apart can remove only what remains free on the entry. On a running balance, it takes from the scope’s free stock, up to what the entry added and has not given back. It answers insufficient_supply if the requested amount exceeds what it can take back. The earlier entry and any movement it recorded remain in the history.

Where to act on it