
- 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.7 KiB
Python
42 lines
1.7 KiB
Python
from datetime import datetime
|
|
from typing import TYPE_CHECKING, List, Optional
|
|
|
|
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, String
|
|
from sqlalchemy.orm import Mapped, relationship
|
|
|
|
from app.db.base_class import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.category import Category
|
|
from app.models.inventory_transaction import InventoryTransaction
|
|
from app.models.supplier import Supplier
|
|
from app.models.user import User
|
|
|
|
|
|
class Product(Base):
|
|
"""
|
|
Database model for products.
|
|
"""
|
|
id = Column(String, primary_key=True, index=True)
|
|
name = Column(String, index=True, nullable=False)
|
|
description = Column(String, nullable=True)
|
|
sku = Column(String, unique=True, index=True, nullable=False)
|
|
price = Column(Float, nullable=False)
|
|
cost = Column(Float, nullable=False)
|
|
quantity = Column(Integer, default=0)
|
|
reorder_level = Column(Integer, default=10)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
# Foreign keys
|
|
category_id = Column(String, ForeignKey("category.id"), nullable=True)
|
|
supplier_id = Column(String, ForeignKey("supplier.id"), nullable=True)
|
|
owner_id = Column(String, ForeignKey("user.id"), nullable=False)
|
|
|
|
# Relationships
|
|
category: Mapped[Optional["Category"]] = relationship("Category", back_populates="products")
|
|
supplier: Mapped[Optional["Supplier"]] = relationship("Supplier", back_populates="products")
|
|
owner: Mapped["User"] = relationship("User", back_populates="products")
|
|
inventory_transactions: Mapped[List["InventoryTransaction"]] = relationship(
|
|
"InventoryTransaction", back_populates="product"
|
|
) |