- New models: WarrantyModel, WalletModel, SystemConfigModel - New schemas: WarrantySchema, RefundSchema, SystemConfig, CrmTaskCalendar, NotificationTemplate, NotificationGateway, RepairErp, ReviewModeration, InventoryPos, MultiDashboard, BillingFinance - New services: WarrantyService, RefundService, CrmService, CrmTaskCalendarService, DeliveryService, EmailTemplateService, InventoryPosService, MultiDashboardService, NotificationGatewayService, RepairErpService, ReviewModerationService, SystemConfigService, TemplateService, CreditService - Updated routers: AdminOrder, BillingFinance, Cart, Catalog, Checkout, Crm, InventoryPos, NotificationGateway, RolePermission, ServiceJob, Settings, Storefront, UserCreation - Updated models: Inventory, Notification, Order, Product, Service, Setting, SystemConfig, User - Updated core: database init, invoice generator, main app - Added WarrantyRouter with full CRUD and claim flow
48 lines
2.4 KiB
Python
48 lines
2.4 KiB
Python
from sqlalchemy import Column, String, Boolean, DateTime, Date, Integer, ForeignKey
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from app.core.database.db_session import Base
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
user_id = Column(String(26), primary_key=True)
|
|
employee_code = Column(String(30), unique=True, nullable=True)
|
|
first_name = Column(String(50), nullable=False)
|
|
last_name = Column(String(50), nullable=False)
|
|
display_name = Column(String(100), nullable=True)
|
|
email = Column(String(150), unique=True, nullable=False)
|
|
phone = Column(String(20), unique=True, nullable=False)
|
|
password_hash = Column(String(255), nullable=False)
|
|
profile_image_id = Column(String(26), nullable=True) # FK defined via alter table or string to avoid circular dependency
|
|
gender = Column(String(20), nullable=True)
|
|
dob = Column(Date, nullable=True)
|
|
|
|
department_id = Column(String(26), ForeignKey("departments.department_id", ondelete="RESTRICT"), nullable=False)
|
|
designation_id = Column(String(26), ForeignKey("designations.designation_id", ondelete="RESTRICT"), nullable=False)
|
|
role_id = Column(String(26), ForeignKey("roles.role_id", ondelete="RESTRICT"), nullable=False)
|
|
manager_id = Column(String(26), ForeignKey("users.user_id", ondelete="SET NULL"), nullable=True)
|
|
|
|
is_active = Column(Boolean, default=True)
|
|
email_verified = Column(Boolean, default=False)
|
|
phone_verified = Column(Boolean, default=False)
|
|
failed_login_attempts = Column(Integer, default=0)
|
|
is_locked = Column(Boolean, default=False)
|
|
last_login = Column(DateTime, nullable=True)
|
|
mfa_secret = Column(String(32), nullable=True)
|
|
mfa_enabled = Column(Boolean, default=False)
|
|
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
deleted_at = Column(DateTime, nullable=True)
|
|
|
|
# Relationships
|
|
department = relationship("Department", foreign_keys=[department_id])
|
|
designation = relationship("Designation", foreign_keys=[designation_id])
|
|
role = relationship("Role", foreign_keys=[role_id])
|
|
manager = relationship("User", remote_side=[user_id], backref="subordinates")
|
|
location_mappings = relationship("UserLocationMapping", back_populates="user", cascade="all, delete-orphan")
|
|
|
|
@property
|
|
def location_ids(self) -> list[str]:
|
|
return [m.location_id for m in self.location_mappings]
|