from datetime import datetime from sqlalchemy import (Boolean, Column, DateTime, Float, ForeignKey, Index, Integer, String, Text, UniqueConstraint) from sqlalchemy.orm import relationship # Import Base from the central database module instead of creating a new one from app.core.database import Base from models.database.base import TimestampMixin class Stock(Base, TimestampMixin): __tablename__ = "stock" id = Column(Integer, primary_key=True, index=True) gtin = Column( String, index=True, nullable=False ) # Foreign key relationship would be ideal location = Column(String, nullable=False, index=True) quantity = Column(Integer, nullable=False, default=0) reserved_quantity = Column(Integer, default=0) # For orders being processed vendor_id = Column(Integer, ForeignKey("vendors.id")) # Optional: vendor -specific stock # Relationships vendor = relationship("Shop") # Composite unique constraint to prevent duplicate GTIN-location combinations __table_args__ = ( UniqueConstraint("gtin", "location", name="uq_stock_gtin_location"), Index( "idx_stock_gtin_location", "gtin", "location" ), # Composite index for efficient queries ) def __repr__(self): return f""