ifixkart-backend/app/models/InventoryLedgerModel.py

22 lines
1.1 KiB
Python

import ulid
from sqlalchemy import Column, String, Integer, DateTime, Index
from sqlalchemy.sql import func
from app.core.database.db_session import Base
class InventoryLedger(Base):
__tablename__ = "inventory_ledger"
ledger_id = Column(String(26), primary_key=True, default=lambda: str(ulid.new()))
variant_id = Column(String(26), nullable=False, index=True)
event_type = Column(String(50), nullable=False, index=True) # RECEIPT, ONLINE_RESERVE, ONLINE_RESERVE_RELEASE, ONLINE_SALE_FROM_RESERVATION, DIRECT_ONLINE_SALE, POS_ALLOCATION, POS_SALE_FROM_ALLOCATION, DIRECT_POS_SALE, RETURN, DAMAGE
qty = Column(Integer, nullable=False)
warehouse_id = Column(String(26), nullable=True)
store_id = Column(String(26), nullable=True)
reference_id = Column(String(100), nullable=True, index=True) # Order ID / POS Tx ID
notes = Column(String(255), nullable=True)
created_at = Column(DateTime, server_default=func.now(), index=True)
__table_args__ = (
Index('idx_ledger_variant_event', 'variant_id', 'event_type', 'created_at'),
)