2025-06-02 11:37:11 +00:00

25 lines
1.0 KiB
Python

from sqlalchemy import Column, ForeignKey, Integer, String, UniqueConstraint
from sqlalchemy.orm import relationship
from app.db.session import Base
class Inventory(Base):
__tablename__ = "inventory"
id = Column(Integer, primary_key=True, index=True)
product_id = Column(Integer, ForeignKey("products.id"), nullable=False)
warehouse_id = Column(Integer, ForeignKey("warehouses.id"), nullable=False)
quantity = Column(Integer, nullable=False, default=0)
location = Column(String) # Specific location within the warehouse (e.g., "Aisle 5, Shelf B")
min_stock_level = Column(Integer, default=0)
max_stock_level = Column(Integer, default=0)
# Ensure a product can only have one inventory record per warehouse
__table_args__ = (
UniqueConstraint('product_id', 'warehouse_id', name='uix_product_warehouse'),
)
# Relationships
product = relationship("Product", back_populates="inventory_items")
warehouse = relationship("Warehouse", back_populates="inventory")