45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
from sqlalchemy import (Boolean, Column, DateTime, Float, ForeignKey, Index,
|
|
Integer, String, Text, UniqueConstraint)
|
|
from sqlalchemy.orm import relationship
|
|
|
|
# Import Base from the central database module instead of creating a new one
|
|
from app.core.database import Base
|
|
from models.database.base import TimestampMixin
|
|
|
|
class Product(Base, TimestampMixin):
|
|
__tablename__ = "products"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False)
|
|
marketplace_product_id = Column(Integer, ForeignKey("marketplace_products.id"), nullable=False)
|
|
|
|
# Shop-specific overrides (can override the main product data)
|
|
product_id = Column(String) # Shop's internal product ID
|
|
price = Column(Float) # Override main product price
|
|
sale_price = Column(Float)
|
|
currency = Column(String)
|
|
availability = Column(String) # Override availability
|
|
condition = Column(String)
|
|
|
|
# Shop-specific metadata
|
|
is_featured = Column(Boolean, default=False)
|
|
is_active = Column(Boolean, default=True)
|
|
display_order = Column(Integer, default=0)
|
|
|
|
# Inventory management
|
|
min_quantity = Column(Integer, default=1)
|
|
max_quantity = Column(Integer)
|
|
|
|
# Relationships
|
|
vendor = relationship("Vendor", back_populates="product")
|
|
marketplace_product = relationship("MarketplaceProduct", back_populates="product")
|
|
|
|
# Constraints
|
|
__table_args__ = (
|
|
UniqueConstraint("vendor_id", "marketplace_product_id", name="uq_product"),
|
|
Index("idx_product_active", "vendor_id", "is_active"),
|
|
Index("idx_product_featured", "vendor_id", "is_featured"),
|
|
)
|