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>
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from sqlalchemy import Boolean, String
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import Base
|
|
|
|
|
|
class Department(Base):
|
|
__tablename__ = "departments"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(100), unique=True)
|
|
# Deactivated values are hidden from new-NCR forms but remain valid on
|
|
# existing records; values referenced by NCRs are never hard-deleted.
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
|
|
class DeviationCategory(Base):
|
|
__tablename__ = "deviation_categories"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(100), unique=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
|
|
|
|
class RootCauseCategory(Base):
|
|
"""Root-cause classification for CAPA trend reporting (API Q1 §6.4.2).
|
|
Seeded with the standard 6M categories; admin-extensible like the other
|
|
lookups."""
|
|
|
|
__tablename__ = "root_cause_categories"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(100), unique=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|