Automated Action a17fe518a9 Implement Small Business Inventory Management System
This commit includes:
- Project structure setup with FastAPI and SQLite
- Database models and schemas for inventory management
- CRUD operations for all entities
- API endpoints for product, category, supplier, and inventory management
- User authentication with JWT tokens
- Initial database migration
- Comprehensive README with setup instructions
2025-06-17 19:02:35 +00:00

41 lines
1.6 KiB
Python

from sqlalchemy import Column, Integer, String, ForeignKey, Float, DateTime, Text
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.db.base_class import BaseClass
from app.db.base import Base
class Inventory(Base, BaseClass):
"""
Inventory model for tracking stock levels of products.
"""
product_id = Column(Integer, ForeignKey("product.id"), nullable=False)
quantity = Column(Integer, nullable=False, default=0)
location = Column(String(255), nullable=True)
last_counted_at = Column(DateTime(timezone=True), nullable=True)
# Relationships
product = relationship("Product", back_populates="inventory_items")
class InventoryTransaction(Base, BaseClass):
"""
Inventory Transaction model for tracking stock movements.
"""
TRANSACTION_TYPES = ["purchase", "sale", "adjustment", "return", "transfer"]
product_id = Column(Integer, ForeignKey("product.id"), nullable=False)
quantity = Column(Integer, nullable=False)
transaction_type = Column(String(50), nullable=False) # purchase, sale, adjustment, return, transfer
reference = Column(String(255), nullable=True) # Order number, invoice number, etc.
unit_price = Column(Float, nullable=True)
notes = Column(Text, nullable=True)
transaction_date = Column(DateTime(timezone=True), server_default=func.now())
# Optional user who performed the transaction
user_id = Column(Integer, ForeignKey("user.id"), nullable=True)
# Relationships
product = relationship("Product")
user = relationship("User")