
- Created project structure with FastAPI framework - Set up SQLite database with SQLAlchemy ORM - Implemented models: User, Item, Supplier, Transaction - Created CRUD operations for all models - Added API endpoints for all resources - Implemented JWT authentication and authorization - Added Alembic migration scripts - Created health endpoint - Updated documentation generated with BackendIM... (backend.im)
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from sqlalchemy import Column, Integer, String, Float, ForeignKey, DateTime, Enum
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
import enum
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class TransactionType(str, enum.Enum):
|
|
PURCHASE = "purchase"
|
|
SALE = "sale"
|
|
ADJUSTMENT = "adjustment"
|
|
RETURN = "return"
|
|
|
|
|
|
class Transaction(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
transaction_type = Column(Enum(TransactionType), nullable=False)
|
|
quantity = Column(Integer, nullable=False)
|
|
price_per_unit = Column(Float, nullable=False)
|
|
|
|
# Reference information
|
|
reference_number = Column(String, nullable=True)
|
|
notes = Column(String, nullable=True)
|
|
|
|
# Timestamps
|
|
transaction_date = Column(DateTime(timezone=True), default=func.now())
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Foreign Keys
|
|
item_id = Column(Integer, ForeignKey("item.id"), nullable=False)
|
|
user_id = Column(Integer, ForeignKey("user.id"), nullable=True)
|
|
|
|
# Relationships
|
|
item = relationship("Item", back_populates="transactions")
|
|
user = relationship("User") |