ifixkart-backend/app/models/SystemConfigModel.py
adithiyan 10bfba7d58 feat: add warranties, refunds, notifications, CRM calendar, system config & delivery modules
- 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
2026-10-13 22:05:16 +05:30

69 lines
3.1 KiB
Python

from datetime import datetime, timezone
from sqlalchemy import Column, String, Integer, Boolean, DateTime, Text, ForeignKey, UniqueConstraint
from sqlalchemy.orm import relationship
import ulid
from app.core.database.db_session import Base
from app.models.audit_base import AuditMixin
from app.models.ProductModel import ProductLocation
from app.models.InventoryPosModel import PosTerminal
from app.models.UserModel import User
class CrmLocation(Base, AuditMixin):
__tablename__ = "crm_locations"
location_id = Column(String(36), primary_key=True, default=lambda: str(ulid.ULID()))
tenant_id = Column(String(36), nullable=False, default="tenant_default", index=True)
name = Column(String(255), nullable=False)
code = Column(String(50), nullable=False, index=True)
address = Column(Text, nullable=True)
city = Column(String(100), nullable=True)
state = Column(String(100), nullable=True)
pincode = Column(String(20), nullable=True)
phone = Column(String(50), nullable=True)
email = Column(String(255), nullable=True)
is_active = Column(Boolean, nullable=False, default=True)
is_primary = Column(Boolean, nullable=False, default=False)
is_central_warehouse = Column(Boolean, nullable=False, default=False)
user_mappings = relationship("UserLocationMapping", back_populates="location", cascade="all, delete-orphan")
product_locations = relationship("ProductLocation", back_populates="location", cascade="all, delete-orphan")
pos_terminals = relationship("PosTerminal", back_populates="location", cascade="all, delete-orphan")
pos_sessions = relationship("CrmPosSession", back_populates="location")
__table_args__ = (
UniqueConstraint("tenant_id", "code", name="uq_tenant_location_code"),
)
class DeviceTypeRegistry(Base, AuditMixin):
__tablename__ = "device_type_registry"
device_type_id = Column(String(36), primary_key=True, default=lambda: str(ulid.ULID()))
tenant_id = Column(String(36), nullable=False, default="tenant_default", index=True)
name = Column(String(100), nullable=False)
code = Column(String(50), nullable=False, index=True)
icon_name = Column(String(50), nullable=True)
display_order = Column(Integer, nullable=False, default=0)
is_active = Column(Boolean, nullable=False, default=True)
# Extended device metadata
category = Column(String(50), nullable=True) # SMARTPHONE, TABLET, LAPTOP, etc.
brand = Column(String(100), nullable=True) # Apple, Samsung, etc.
device_name = Column(String(255), nullable=True) # Full device name
__table_args__ = (
UniqueConstraint("tenant_id", "code", name="uq_tenant_device_code"),
)
class UserLocationMapping(Base):
__tablename__ = "user_location_mappings"
user_id = Column(String(36), ForeignKey("users.user_id", ondelete="CASCADE"), primary_key=True)
location_id = Column(String(36), ForeignKey("crm_locations.location_id", ondelete="CASCADE"), primary_key=True)
is_primary = Column(Boolean, nullable=False, default=False)
user = relationship("User", back_populates="location_mappings")
location = relationship("CrmLocation", back_populates="user_mappings")