
- Fix unused imports in API endpoints - Add proper __all__ exports in model and schema modules - Add proper TYPE_CHECKING imports in models to prevent circular imports - Fix import order in migrations - Fix long lines in migration scripts - All ruff checks passing
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from datetime import datetime
|
|
from enum import Enum as PyEnum
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import Column, DateTime, Enum, Float, ForeignKey, Integer, String
|
|
from sqlalchemy.orm import Mapped, relationship
|
|
|
|
from app.db.base_class import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.product import Product
|
|
|
|
|
|
class TransactionType(str, PyEnum):
|
|
"""
|
|
Enum for inventory transaction types.
|
|
"""
|
|
PURCHASE = "purchase"
|
|
SALE = "sale"
|
|
ADJUSTMENT = "adjustment"
|
|
RETURN = "return"
|
|
TRANSFER = "transfer"
|
|
|
|
|
|
class InventoryTransaction(Base):
|
|
"""
|
|
Database model for inventory transactions.
|
|
"""
|
|
id = Column(String, primary_key=True, index=True)
|
|
transaction_type = Column(Enum(TransactionType), nullable=False)
|
|
quantity = Column(Integer, nullable=False)
|
|
transaction_date = Column(DateTime, default=datetime.utcnow)
|
|
notes = Column(String, nullable=True)
|
|
unit_price = Column(Float, nullable=True)
|
|
reference_number = Column(String, nullable=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
# Foreign keys
|
|
product_id = Column(String, ForeignKey("product.id"), nullable=False)
|
|
|
|
# Relationships
|
|
product: Mapped["Product"] = relationship("Product", back_populates="inventory_transactions") |