Context for the warehouse turnover report (§8, no export — see
Web.TurnoverReportLive).
compute/3 derives per-item inflow/outflow totals for a date window by
reading the lines of already-posted documents — GoodsReceipt,
GoodsIssue, Transfer, and InventoryDocument — there is no separate
ledger/journal table in the module to query instead.
Only items with nonzero inflow or outflow in the window are returned:
the base item set is the union of items appearing in a posted movement,
not every item with a Stock row — an item sitting untouched in the
warehouse for the whole period isn't part of a movement report. balance
is then looked up per item on top of that set, not the other way around.
Wave-1 limitations
balanceis the item's current on-hand quantity (fromStockLedger.stock_map/0orstock_map_for_location/1), NOT a historical balance as ofdate_to. Reconstructing a point-in-time balance would require a ledger/journal of every stock-affecting event in order, which the module doesn't have — this is an accepted wave-1 limitation, not a bug. Re-surface it in the UI (seeWeb.TurnoverReportLive), don't just document it here.balancedoesn't see stock "in transit" on an unfinished (in_transit)Transfer— same limitation asDeficits.available_by_item/0.- A
Transferthat shipped (counted as outflow viashipped_at) and was LATER cancelled fromin_transit— crediting the quantity back to the source, seeTransfers.cancel_transfer/2— still counts as an outflow here ifshipped_atfalls in the window: the cancellation's reversal credit isn't a receipt, a transfer receive, or an inventory count, so it isn't one of the fields this report reads. Not compensated for in wave 1. posted_at/shipped_at/received_atare not indexed on the underlying tables, socompute/3's date-range scan gets slower as document volume grows. A known tech-debt item (to be recorded indev_docs/DEVELOPMENT_PLAN.md— see T22), not fixed here.
Summary
Functions
Computes per-item turnover for the closed window [date_from, date_to]
(both Date, inclusive), optionally scoped to a single warehouse via
location_uuid (nil sums every warehouse).
Returns a list of %{item_uuid:, name:, sku:, unit:, inflow:, outflow:, balance:}, inflow/outflow/balance all Decimal, one entry per item
that had a posted movement in the window (see moduledoc for exactly what
counts, and for the balance limitations).