Repository navigation
F10: Mortality/culling — bird movement ledger + current flock counts (#54) - #55
Merged
Merged
Conversation
added 2 commits
July 16, 2026 14:54
…54) Daily entry captured a mortality count that went nowhere and flock counts never moved from InitialCount. Domain - BirdMovement: append-only ledger row (flock, date, type Mortality/Cull/Adjustment, quantity = birds removed, note). Rows are immutable — corrections are new Adjustment rows (which may be negative to add birds back) — so no Version token per the aggregate-mutation rule's rationale. Application - SubmitDailyEntry also writes a Mortality movement for the entry's date when MortalityCount > 0, in the same transaction as egg lots: the existing submit Version race covers it, so a losing submit rolls back its movement with its lots. Draft mortality is not a movement (submit freezes the day). - RecordBirdMovement handler for manual Cull/Adjustment; manual Mortality is rejected (would double-count at submit). Flock lifecycle gate reuses CanRecordProductionOn: depleted flocks accept backfill dated on/before depletion, archived accept nothing. API - POST/GET /flocks/{id}/movements (paged, newest first; 404 for unknown/foreign flocks). - Flock responses gain CurrentBirds = InitialCount − Σ quantities; list uses one grouped query. Web - Flocks screen: Birds column shows current count (initial alongside once they differ); per-flock "birds" ledger panel with movement history and a cull/adjustment form. Scoped idempotency keys, refresh-before-rotation. Tests (+4 -> 119): submit generates exactly one movement and zero- mortality days none, draft mortality not counted, cull + negative adjustment math on get and list, validation and lifecycle gating, parallel-submit race leaves exactly one movement. Verified in chromium against the real stack: submit with mortality dropped House 2 400->394 on the Flocks screen; cull -> 384; negative adjustment -> 386; ledger shows all three row types. Closes #54
- Backfill migration: entries submitted before this feature carried mortality that the new ledger-derived CurrentBirds would silently forget. The EntryRef migration inserts Mortality rows for existing non-Draft entries; the NOT EXISTS guard covers both the new back-reference and same-flock/date rows created between the two migrations. (codex P1) - BirdMovement.DailyEntryId back-reference on generated rows (FK, nullable) — the reconciliation hook the future manager-adjust flow needs to find the ledger side of a corrected entry. (pi Medium) - Submit now applies the same lifecycle gate as recording: an archived flock's leftover draft can no longer mint lots + a mortality row; depleted-flock backfill drafts still submit when dated on/before DepletedOn. (pi Low) - Repository Update/Remove throw NotSupportedException — the append-only invariant is enforced at the seam, not just by convention. (pi Low) - FlocksPage: ledger fetches are guarded by the currently-open flock id, so a slow response for flock A can't render under flock B's heading or clobber a post-write refresh. Cull quantity input gets min=1. (codex P2, pi Low) 120 tests green; backfill verified against the dev DB: a pre-feature submitted entry gained a back-referenced Mortality row and an existing movement was not duplicated.
Owner
Author
Review round: codex + pi
120 tests green after fixes (+1: archived-draft submit rejected / depleted backfill draft still submits; back-reference asserted in the submit test). |
This was referenced Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #54. Phase 1.1 slice (epic #14): "Mortality/culling + bird movement generation".
What
Mortality/Cull/Adjustment), quantity (birds removed; Adjustment may be negative), note. Immutable — corrections are new rows, so no Version token.SubmitDailyEntrywrites aMortalitymovement alongside egg lots in the same transaction — the existing submit Version race covers it (losing submit rolls back movement + lots together). Draft mortality is not a movement.POST /flocks/{id}/movementsfor Cull/Adjustment; manualMortalityrejected (would double-count at submit). Lifecycle gate reusesCanRecordProductionOnfrom F7: Flock management — edit/deplete/archive + Flocks screen #47 — depleted flocks accept backfill dated on/before depletion, archived accept nothing.CurrentBirds = InitialCount − Σ quantities(one grouped query for lists). Flocks screen shows current count with initial alongside once they differ, plus a per-flock ledger panel with movement history and a cull/adjustment form.Out of scope (per issue)
Transfers (houses phantom until Phase 2), auto-zero on deplete, feed/water.
Tests (+4 → 119)
Submit generates exactly one movement / zero-mortality days none / draft mortality not counted; cull + negative-adjustment math on get and list; validation (manual Mortality 400, zero qty, negative cull) and lifecycle gating (backfill OK, post-depletion 422, archived 422, unknown flock 404); parallel-submit race leaves exactly one movement.
Verification (chromium, real stack)
Submitted an entry with mortality 6 → Flocks screen 400→394; recorded a 10-bird cull → 384; −2 adjustment → 386. Ledger panel shows all three row types with signed quantities.