Aller au contenu
login
arrow_backRetour aux issues
YosemiteCrew/openrunic #97

Lot status has no history, so as-of queries use today's value

ecoDébutant bug help wanted

descriptionDescription

## What `StockLot.status` and the package's `Lot.status` are a single mutable value with no history, so every as-of question is answered with today's status. A lot retired on 10 September is excluded from `fefo(lots, '2026-09-01')` even though it was available on the 1st. Back-dated allocation and reconciliation therefore cannot reproduce what could actually have been drawn on the event date - which is the whole purpose of the as-of contract `packages/inventory/src/lots.ts` opens with. Raised in review of [#90](https://github.com/YosemiteCrew/openrunic/pull/90). Three sibling findings in the same class were fixed in [#96](https://github.com/YosemiteCrew/openrunic/pull/96) - the beyond-use clock, the receipt date, and `isUsable` disagreeing with `fefo`. This one is left because it needs a schema change rather than a code fix, and because the shape of that change is a real decision. ## Why it matters more than it looks The direction is the dangerous one. A lot quarantined today drops out of a query about last month, so a reconciliation of last month's count comes up short against a shelf that was correct - and the discrepancy points at nothing, because the lot that explains it has been filtered out of the answer. ## The shapes available **A status-history table.** `StockLotStatusChange(lotId, status, effectiveFrom, actorId, reason)`, and the package takes the status in force at `asOf`. Complete and truthful; it also changes `Lot` from a value to something that needs resolving before it can be judged, which touches every entry point. **An effective-from pair on the lot.** `statusFrom` alongside `status`, answering "since when" but not "what before". Cheap, and it degrades to the current behaviour for anything older than the last change - so it answers the September question only if nothing has changed since. **Leave it, and say so.** The as-of contract would need an explicit carve-out naming status as the one field judged at read time. Honest, and it makes every back-dated report quietly approximate. The first is preferred. Status changes on a lot are rare - a recall, a quarantine, a retirement - so the table stays small, and it is the only shape that makes a back-dated report reproducible, which is what the contract promises. ## Acceptance - `fefo(lots, '2026-09-01')` includes a lot that was AVAILABLE on the 1st and RETIRED on the 10th, and excludes it from a query about the 20th - `unusableReason` names the status that was in force, and when it changed - The as-of header in `lots.ts` stops needing a carve-out - A status change is attributable: who, when, why - a recall is a patient-safety event and the record should say who acted on it
codeOuvre sur GitHub