
- Set up project structure with FastAPI and SQLite - Create database models for inventory management - Set up SQLAlchemy and Alembic for database migrations - Create initial database migrations - Implement CRUD operations for products, categories, suppliers - Implement stock movement tracking and inventory management - Add authentication and user management - Add API endpoints for all entities - Add health check endpoint - Update README with project information and usage instructions
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from sqlalchemy import Column, String, Integer, Float, DateTime, Text, ForeignKey, Enum
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
import enum
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class MovementType(str, enum.Enum):
|
|
PURCHASE = "purchase"
|
|
SALE = "sale"
|
|
ADJUSTMENT = "adjustment"
|
|
RETURN = "return"
|
|
INITIAL = "initial"
|
|
|
|
|
|
class StockMovement(Base):
|
|
id = Column(String, primary_key=True, index=True)
|
|
|
|
product_id = Column(String, ForeignKey("product.id"), nullable=False)
|
|
product = relationship("Product", backref="stock_movements")
|
|
|
|
quantity = Column(Integer, nullable=False)
|
|
unit_price = Column(Float, nullable=True)
|
|
|
|
movement_type = Column(Enum(MovementType), nullable=False)
|
|
reference = Column(String, nullable=True) # Reference to purchase order, invoice, etc.
|
|
|
|
notes = Column(Text, nullable=True)
|
|
|
|
created_by = Column(String, ForeignKey("user.id"), nullable=True)
|
|
user = relationship("User", backref="stock_movements")
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now()) |