Automated Action 5935f302dc Create Small Business Inventory Management System with FastAPI and SQLite
- Set up project structure and FastAPI application
- Create database models with SQLAlchemy
- Implement authentication with JWT
- Add CRUD operations for products, inventory, categories
- Implement purchase order and sales functionality
- Create reporting endpoints
- Set up Alembic for database migrations
- Add comprehensive documentation in README.md
2025-05-16 08:53:15 +00:00

29 lines
1.2 KiB
Python

from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.db.base_class import Base
class Inventory(Base):
id = Column(Integer, primary_key=True, index=True)
product_id = Column(Integer, ForeignKey("product.id"), nullable=False)
quantity = Column(Integer, nullable=False, default=0)
location = Column(String, nullable=True)
# Relationships
product = relationship("Product", back_populates="inventory_items")
class InventoryTransaction(Base):
id = Column(Integer, primary_key=True, index=True)
product_id = Column(Integer, ForeignKey("product.id"), nullable=False)
quantity = Column(Integer, nullable=False) # Can be positive or negative
transaction_type = Column(String, nullable=False) # purchase, sale, adjustment
reference_id = Column(Integer, nullable=True) # ID of related transaction
reason = Column(String, nullable=True)
timestamp = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
location = Column(String, nullable=True)
# Relationships
product = relationship("Product")