Skip to content

F17: Edit submitted daily entries — lock job + manager adjust with lot/movement reconciliation #69

Description

@mforce

Part of Phase 1.1 (epic #14). Spec §8.1 (entry states + who can edit), §9.5 (voided entry → reversing movement). The domain half already exists: DailyEntry carries the full state enum, Lock(), and ManagerAdjust(totals, reason, grades) with grade validation and a Version bump — nothing above it is wired, so today no one can correct a submitted entry.

Scope

Auto-lock (spec §8.1 default):

Adjust submitted/locked entries:

  • POST /daily-entries/{id}/adjust — body: totals (total/cracked/dirty/discarded/mortality), optional grade lines, required reason (≤500, whitespace-guarded). Admin-only until RBAC lands (single login today — enforce role check when EPIC: Phase 1.1 — Operational fill #14 RBAC ships; leave TODO seam).
  • Spec allows managers to edit submitted pre-lock; MVP simplification: one adjust path for both Submitted and Locked → both land in ManagerAdjusted (domain currently requires Locked — relax to Submitted|Locked, keep the reason mandatory).
  • Downstream reconciliation (the hard part):
    • Egg lots: diff old vs new grade quantities per (entry, grade). Growing a lot is safe; shrinking below QuantityProduced − QuantityAvailable (already sold/allocated) → 422 with a message naming the blocking allocation. Same pessimistic FOR UPDATE + canonical lock ordering as confirm/void (F14: Void confirmed sales order — return allocated stock #60/PR F14: Void confirmed sales order — return allocated stock (#60) #64).
    • Mortality: if MortalityCount changes, append a compensating Mortality bird-movement delta tied to the entry (ledger stays append-only — no edits of the original row).
    • All of it in one transaction with the entry's Version race-tested per AGENTS.md.
  • Adjust reason + previous values surfaced in the entry response (audit trail until the audit-log slice lands).

Void entry (spec §8.1/§9.5):

SPA:

  • History page: adjust/void actions on Submitted/Locked entries behind F13-style confirm + required reason; Locked/ManagerAdjusted/Voided badges; adjusted entries show reason.

Out of scope

Acceptance

  • Entry submitted 8+ farm-local days ago is Locked automatically; adjust on it lands as ManagerAdjusted with reason; totals/lots/stock all consistent afterwards.
  • Shrinking a grade below its already-sold quantity → 422, nothing changes.
  • Adjust mortality 2→5 → bird ledger shows the original 2 plus a +3 compensating movement; CurrentBirds correct.
  • Void entry with unsold lots → stock drops by those lots, entry Voided, lots emptied; void with sold stock → 422.
  • Parallel adjusts: exactly one wins (Version delta 1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions