
- 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
31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
from sqlalchemy import Column, Integer, String, Text, Numeric, ForeignKey, DateTime
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class PurchaseOrder(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
supplier_name = Column(String, nullable=False)
|
|
notes = Column(Text, nullable=True)
|
|
status = Column(String, nullable=False, default="pending") # pending, received, cancelled
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now(), nullable=True)
|
|
created_by = Column(Integer, ForeignKey("user.id"), nullable=False)
|
|
|
|
# Relationships
|
|
items = relationship("PurchaseOrderItem", back_populates="purchase_order", cascade="all, delete-orphan")
|
|
created_by_user = relationship("User", back_populates="purchase_orders")
|
|
|
|
|
|
class PurchaseOrderItem(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
purchase_order_id = Column(Integer, ForeignKey("purchaseorder.id"), nullable=False)
|
|
product_id = Column(Integer, ForeignKey("product.id"), nullable=False)
|
|
quantity = Column(Integer, nullable=False)
|
|
unit_price = Column(Numeric(precision=10, scale=2), nullable=False)
|
|
|
|
# Relationships
|
|
purchase_order = relationship("PurchaseOrder", back_populates="items")
|
|
product = relationship("Product", back_populates="purchase_order_items") |