47 lines
2.0 KiB
Python
47 lines
2.0 KiB
Python
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Text, Enum, JSON
|
|
from sqlalchemy.orm import relationship
|
|
from app.db.database import Base
|
|
import enum
|
|
|
|
class NCLevel(str, enum.Enum):
|
|
CRITICAL = "critical"
|
|
MAJOR = "major"
|
|
MINOR = "minor"
|
|
|
|
class NCType(str, enum.Enum):
|
|
HUMAN_ERROR = "Errores humanos"
|
|
PROCESS_FAILURE = "Fallas en los procesos"
|
|
DESIGN_ISSUE = "Problemas de diseño"
|
|
UNCONTROLLED_CHANGE = "Cambios no controlados"
|
|
COMMUNICATION_FAILURE = "Falta de comunicación"
|
|
|
|
class NonConformity(Base):
|
|
__tablename__ = "non_conformities"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
activity_id = Column(Integer, ForeignKey("activities.id"))
|
|
level = Column(Enum(NCLevel), default=NCLevel.MINOR)
|
|
description = Column(Text, nullable=False)
|
|
status = Column(String, default="open") # open, closed
|
|
|
|
# New Fields
|
|
due_date = Column(DateTime, nullable=True)
|
|
responsible_person = Column(String, nullable=True) # Legend/Name
|
|
responsible_email = Column(String, nullable=True) # For guest access
|
|
access_hash = Column(String, unique=True, index=True, nullable=True)
|
|
contractor_id = Column(Integer, ForeignKey("contractors.id"), nullable=True)
|
|
|
|
action_checklist = Column(JSON, nullable=True) # List of dicts {text: str, completed: bool}
|
|
nc_type = Column(Enum(NCType), nullable=True)
|
|
impact_description = Column(Text, nullable=True)
|
|
closure_description = Column(Text, nullable=True)
|
|
guest_actions = Column(Text, nullable=True) # Field for guest to describe actions taken
|
|
|
|
parent_id = Column(Integer, ForeignKey("non_conformities.id"), nullable=True)
|
|
|
|
activity = relationship("app.models.activity.Activity", back_populates="non_conformities")
|
|
contractor = relationship("app.models.contractor.Contractor")
|
|
evidences = relationship("Evidence", back_populates="non_conformity")
|
|
parent = relationship("NonConformity", remote_side=[id], back_populates="child_ncs")
|
|
child_ncs = relationship("NonConformity", back_populates="parent")
|