major refactoring adding vendor and customer features
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from sqlalchemy import (Boolean, Column, ForeignKey, Integer, String, Text)
|
||||
from sqlalchemy import (Boolean, Column, ForeignKey, Integer, String, Text, JSON)
|
||||
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
|
||||
|
||||
@@ -13,15 +12,22 @@ class Vendor(Base, TimestampMixin):
|
||||
vendor_code = Column(
|
||||
String, unique=True, index=True, nullable=False
|
||||
) # e.g., "TECHSTORE", "FASHIONHUB"
|
||||
vendor_name = Column(String, nullable=False) # Display name
|
||||
subdomain = Column(String(100), unique=True, nullable=False, index=True)
|
||||
name = Column(String, nullable=False) # Display name
|
||||
description = Column(Text)
|
||||
owner_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
owner_user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
theme_config = Column(JSON, default=dict)
|
||||
|
||||
# Contact information
|
||||
contact_email = Column(String)
|
||||
contact_phone = Column(String)
|
||||
website = Column(String)
|
||||
|
||||
# Letzshop URLs - multi-language support
|
||||
letzshop_csv_url_fr = Column(String)
|
||||
letzshop_csv_url_en = Column(String)
|
||||
letzshop_csv_url_de = Column(String)
|
||||
|
||||
# Business information
|
||||
business_address = Column(Text)
|
||||
tax_number = Column(String)
|
||||
@@ -32,7 +38,47 @@ class Vendor(Base, TimestampMixin):
|
||||
|
||||
# Relationships
|
||||
owner = relationship("User", back_populates="owned_vendors")
|
||||
product = relationship("Product", back_populates="vendor")
|
||||
marketplace_import_jobs = relationship(
|
||||
"MarketplaceImportJob", back_populates="vendor"
|
||||
)
|
||||
vendor_users = relationship("VendorUser", back_populates="vendor")
|
||||
products = relationship("Product", back_populates="vendor")
|
||||
customers = relationship("Customer", back_populates="vendor")
|
||||
orders = relationship("Order", back_populates="vendor")
|
||||
marketplace_import_jobs = relationship("MarketplaceImportJob", back_populates="vendor")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Vendor(id={self.id}, vendor_code='{self.vendor_code}', name='{self.name}', subdomain='{self.subdomain}')>"
|
||||
|
||||
|
||||
class VendorUser(Base, TimestampMixin):
|
||||
__tablename__ = "vendor_users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
role_id = Column(Integer, ForeignKey("roles.id"), nullable=False)
|
||||
invited_by = Column(Integer, ForeignKey("users.id"))
|
||||
is_active = Column(Boolean, default=True, nullable=False)
|
||||
|
||||
# Relationships
|
||||
vendor = relationship("Vendor", back_populates="vendor_users")
|
||||
user = relationship("User", foreign_keys=[user_id], back_populates="vendor_memberships")
|
||||
inviter = relationship("User", foreign_keys=[invited_by])
|
||||
role = relationship("Role", back_populates="vendor_users")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<VendorUser(vendor_id={self.vendor_id}, user_id={self.user_id})>"
|
||||
|
||||
|
||||
class Role(Base, TimestampMixin):
|
||||
__tablename__ = "roles"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=False)
|
||||
name = Column(String(100), nullable=False) # "Owner", "Manager", "Editor", "Viewer"
|
||||
permissions = Column(JSON, default=list) # ["products.create", "orders.view", etc.]
|
||||
|
||||
# Relationships
|
||||
vendor = relationship("Vendor")
|
||||
vendor_users = relationship("VendorUser", back_populates="role")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Role(id={self.id}, name='{self.name}', vendor_id={self.vendor_id})>"
|
||||
Reference in New Issue
Block a user