Add API Q1 CAPA: root cause, corrective action gate, effectiveness verification #1

Merged
spencerm merged 1 commits from feature/api-q1-capa into main 2026-08-04 19:52:19 +00:00
Owner

Implements the tester feedback against API Q1 §5.9.1.2 / §6.4.2.

What's included

  1. Root Cause field — separate from Deviation Detail (captures why, not what)
  2. Corrective Action Required? (Yes/No) — required gate on every NCR with a brief justification, enforced server-side
  3. Corrective Action Plan — plan text, owner (emailed on assignment), and due date
  4. Effectiveness Verification — result + notes with server-stamped verifier/date; costing returns 409 and cannot close the NCR until the action is verified effective
  5. Recurring Issue flag — bidirectional NCR-to-NCR links; prior NCRs show a warning when later NCRs reference them
  6. Root Cause Category — 6M lookup (Man/Machine/Method/Material/Measurement/Environment), admin-manageable, separate from Deviation Category
  7. Dashboard metrics — % root cause completed, % CAPA verified effective, avg CAPA close time, overdue CAPA count, plus an NCRs-by-root-cause-category chart

Design notes

  • CAPA is a cross-stage section (POST /ncrs/{ref}/capa, editable by QC Inspectors / Disposition Authorities / Admins before closure) rather than a new workflow stage — partial saves by different roles are fine; the gate is enforced once, at the costing action that closes the NCR.
  • Every field change is audit-logged; verification is stamped server-side.
  • Also updated: CSV export, printable PDF, vw_ncr_full Power BI view (migration 0004), seed data, README.
  • Migration 0003 seeds the 6M categories so upgraded deployments get them without re-running app.seed.

Testing

  • cd backend && pytest41/41 pass, including new test_capa.py (gate blocking/unblocking, justification rule, verification stamping, link validation, role enforcement, metrics, CSV columns)
  • npm run build — clean
  • Verified end-to-end in the browser: closing an NCR with an unverified CAPA is blocked with a clear message; after recording verification the gate banner turns green and the NCR closes; report tiles update live

Heads-up for testers

Any NCR already sitting in Costing when this deploys will be blocked from closing until someone answers the CA question — that's the Q1 gate working as intended, not a bug.

🤖 Generated with Claude Code

Implements the tester feedback against **API Q1 §5.9.1.2 / §6.4.2**. ## What's included 1. **Root Cause field** — separate from Deviation Detail (captures *why*, not *what*) 2. **Corrective Action Required? (Yes/No)** — required gate on every NCR with a brief justification, enforced server-side 3. **Corrective Action Plan** — plan text, owner (emailed on assignment), and due date 4. **Effectiveness Verification** — result + notes with server-stamped verifier/date; costing returns **409** and cannot close the NCR until the action is verified *effective* 5. **Recurring Issue flag** — bidirectional NCR-to-NCR links; prior NCRs show a warning when later NCRs reference them 6. **Root Cause Category** — 6M lookup (Man/Machine/Method/Material/Measurement/Environment), admin-manageable, separate from Deviation Category 7. **Dashboard metrics** — % root cause completed, % CAPA verified effective, avg CAPA close time, overdue CAPA count, plus an NCRs-by-root-cause-category chart ## Design notes - CAPA is a **cross-stage section** (`POST /ncrs/{ref}/capa`, editable by QC Inspectors / Disposition Authorities / Admins before closure) rather than a new workflow stage — partial saves by different roles are fine; the gate is enforced once, at the costing action that closes the NCR. - Every field change is audit-logged; verification is stamped server-side. - Also updated: CSV export, printable PDF, `vw_ncr_full` Power BI view (migration 0004), seed data, README. - Migration 0003 seeds the 6M categories so upgraded deployments get them without re-running `app.seed`. ## Testing - `cd backend && pytest` — **41/41 pass**, including new `test_capa.py` (gate blocking/unblocking, justification rule, verification stamping, link validation, role enforcement, metrics, CSV columns) - `npm run build` — clean - Verified end-to-end in the browser: closing an NCR with an unverified CAPA is blocked with a clear message; after recording verification the gate banner turns green and the NCR closes; report tiles update live ## Heads-up for testers Any NCR already sitting in **Costing** when this deploys will be blocked from closing until someone answers the CA question — that's the Q1 gate working as intended, not a bug. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
spencerm added 1 commit 2026-08-04 19:50:05 +00:00
Implements tester feedback against API Q1 §5.9.1.2 / §6.4.2:

- Root Cause field + 6M Root Cause Category lookup (Man/Machine/Method/
  Material/Measurement/Environment), separate from Deviation Detail/Category
- "Corrective Action Required?" Yes/No gate on every NCR with a required
  justification
- Corrective action plan with owner + due date; owner is notified by email
- Effectiveness verification (result, notes, server-stamped verifier/date)
  required before an NCR can close when corrective action is required —
  costing returns 409 listing the missing pieces
- Recurring-issue flag with bidirectional NCR-to-NCR links; prior NCRs show
  a warning when later NCRs reference them
- Dashboard metrics: % root cause completed, % CAPA verified effective,
  avg CAPA close time, overdue CAPA count, NCRs by root cause category
- CAPA section in the NCR detail UI, printable PDF, CSV export, and the
  vw_ncr_full Power BI view; admin list manager for root cause categories
- Migrations 0003 (schema + seeded 6M lookup) and 0004 (view refresh);
  demo seed data exercises every metric

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
spencerm merged commit 281536fd73 into main 2026-08-04 19:52:19 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: spencerm/pesco-ncr#1