40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from sqlalchemy import (
|
|
Boolean,
|
|
Column,
|
|
DateTime,
|
|
Float,
|
|
ForeignKey,
|
|
Integer,
|
|
String,
|
|
Text,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class Product(Base):
|
|
__tablename__ = "products"
|
|
|
|
id = Column(String, primary_key=True, index=True)
|
|
name = Column(String, index=True, nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
sku = Column(String, unique=True, index=True, nullable=True)
|
|
barcode = Column(String, unique=True, index=True, nullable=True)
|
|
price = Column(Float, nullable=False, default=0.0)
|
|
cost_price = Column(Float, nullable=True)
|
|
current_stock = Column(Integer, nullable=False, default=0)
|
|
min_stock_level = Column(Integer, nullable=True)
|
|
max_stock_level = Column(Integer, nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
category_id = Column(String, ForeignKey("categories.id"), nullable=True)
|
|
supplier_id = Column(String, ForeignKey("suppliers.id"), nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationships
|
|
category = relationship("Category", back_populates="products")
|
|
supplier = relationship("Supplier", back_populates="products")
|
|
inventory_movements = relationship("InventoryMovement", back_populates="product")
|