| """ |
| SQLAlchemy models for attendance tracking. |
| """ |
| from sqlalchemy import Column, String, Integer, Float, Date, BigInteger, TIMESTAMP, Index |
| from sqlalchemy.dialects.postgresql import UUID |
| from sqlalchemy.sql import func |
| import uuid |
|
|
| from app.core.database import Base |
|
|
|
|
| class ScmAttendance(Base): |
| """ |
| Attendance tracking model. |
| One row per employee per day. |
| """ |
| __tablename__ = "scm_attendance" |
| __table_args__ = ( |
| Index('idx_scm_attendance_work_date', 'employee_id', 'work_date'), |
| Index('idx_scm_attendance_merchant', 'merchant_id', 'work_date'), |
| {'schema': 'trans'} |
| ) |
|
|
| id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) |
| merchant_id = Column(UUID(as_uuid=True), nullable=False) |
| employee_id = Column(UUID(as_uuid=True), nullable=False) |
| work_date = Column(Date, nullable=False) |
| |
| |
| check_in_time = Column(BigInteger, nullable=True) |
| check_in_lat = Column(Float, nullable=True) |
| check_in_lon = Column(Float, nullable=True) |
| check_in_geofence_id = Column(UUID(as_uuid=True), nullable=True) |
| |
| |
| check_out_time = Column(BigInteger, nullable=True) |
| check_out_lat = Column(Float, nullable=True) |
| check_out_lon = Column(Float, nullable=True) |
| |
| |
| total_minutes = Column(Integer, nullable=True) |
| |
| |
| created_at = Column(TIMESTAMP, server_default=func.now(), nullable=False) |
| updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now(), nullable=False) |
|
|
| def __repr__(self): |
| return f"<ScmAttendance(id={self.id}, employee_id={self.employee_id}, work_date={self.work_date})>" |
|
|