major refactoring adding vendor and customer features
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
# models/database/product.py
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import (Boolean, Column, DateTime, Float, ForeignKey, Index,
|
||||
Integer, String, Text, UniqueConstraint)
|
||||
from sqlalchemy import Boolean, Column, Float, ForeignKey, Index, Integer, String, 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"
|
||||
|
||||
@@ -15,12 +14,12 @@ class Product(Base, TimestampMixin):
|
||||
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False)
|
||||
marketplace_product_id = Column(Integer, ForeignKey("marketplace_products.id"), nullable=False)
|
||||
|
||||
# Vendor-specific overrides (can override the main product data)
|
||||
product_id = Column(String) # Vendor's internal product ID
|
||||
price = Column(Float) # Override main product price
|
||||
# Vendor-specific overrides
|
||||
product_id = Column(String) # Vendor's internal SKU
|
||||
price = Column(Float)
|
||||
sale_price = Column(Float)
|
||||
currency = Column(String)
|
||||
availability = Column(String) # Override availability
|
||||
availability = Column(String)
|
||||
condition = Column(String)
|
||||
|
||||
# Vendor-specific metadata
|
||||
@@ -28,13 +27,14 @@ class Product(Base, TimestampMixin):
|
||||
is_active = Column(Boolean, default=True)
|
||||
display_order = Column(Integer, default=0)
|
||||
|
||||
# Inventory management
|
||||
# Inventory settings
|
||||
min_quantity = Column(Integer, default=1)
|
||||
max_quantity = Column(Integer)
|
||||
|
||||
# Relationships
|
||||
vendor = relationship("Vendor", back_populates="product")
|
||||
vendor = relationship("Vendor", back_populates="products")
|
||||
marketplace_product = relationship("MarketplaceProduct", back_populates="product")
|
||||
inventory_entries = relationship("Inventory", back_populates="product", cascade="all, delete-orphan")
|
||||
|
||||
# Constraints
|
||||
__table_args__ = (
|
||||
@@ -42,3 +42,16 @@ class Product(Base, TimestampMixin):
|
||||
Index("idx_product_active", "vendor_id", "is_active"),
|
||||
Index("idx_product_featured", "vendor_id", "is_featured"),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Product(id={self.id}, vendor_id={self.vendor_id}, product_id='{self.product_id}')>"
|
||||
|
||||
@property
|
||||
def total_inventory(self):
|
||||
"""Calculate total inventory across all locations."""
|
||||
return sum(inv.quantity for inv in self.inventory_entries)
|
||||
|
||||
@property
|
||||
def available_inventory(self):
|
||||
"""Calculate available inventory (total - reserved)."""
|
||||
return sum(inv.available_quantity for inv in self.inventory_entries)
|
||||
|
||||
Reference in New Issue
Block a user