
Features include: - User management with JWT authentication and role-based access - Inventory items with SKU/barcode tracking and stock management - Categories and suppliers organization - Inventory transactions with automatic stock updates - Low stock alerts and advanced search/filtering - RESTful API with comprehensive CRUD operations - SQLite database with Alembic migrations - Auto-generated API documentation Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from sqlalchemy import Column, Integer, String, Text, Float, ForeignKey, DateTime
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from app.db.base import Base
|
|
|
|
class InventoryItem(Base):
|
|
__tablename__ = "inventory_items"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, index=True, nullable=False)
|
|
description = Column(Text)
|
|
sku = Column(String, unique=True, index=True, nullable=False)
|
|
barcode = Column(String, unique=True, index=True)
|
|
|
|
# Pricing
|
|
cost_price = Column(Float, nullable=False, default=0.0)
|
|
selling_price = Column(Float, nullable=False, default=0.0)
|
|
|
|
# Stock management
|
|
quantity_in_stock = Column(Integer, nullable=False, default=0)
|
|
minimum_stock_level = Column(Integer, nullable=False, default=0)
|
|
maximum_stock_level = Column(Integer)
|
|
|
|
# Foreign Keys
|
|
category_id = Column(Integer, ForeignKey("categories.id"))
|
|
supplier_id = Column(Integer, ForeignKey("suppliers.id"))
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationships
|
|
category = relationship("Category", back_populates="items")
|
|
supplier = relationship("Supplier", back_populates="items")
|
|
transactions = relationship("InventoryTransaction", back_populates="item")
|
|
|
|
@property
|
|
def is_low_stock(self):
|
|
return self.quantity_in_stock <= self.minimum_stock_level |