
- 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.3 KiB
Python
31 lines
1.3 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 Sale(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
customer_name = Column(String, nullable=True)
|
|
notes = Column(Text, nullable=True)
|
|
status = Column(String, nullable=False, default="completed") # completed, cancelled, returned
|
|
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("SaleItem", back_populates="sale", cascade="all, delete-orphan")
|
|
created_by_user = relationship("User", back_populates="sales")
|
|
|
|
|
|
class SaleItem(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
sale_id = Column(Integer, ForeignKey("sale.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
|
|
sale = relationship("Sale", back_populates="items")
|
|
product = relationship("Product", back_populates="sale_items") |