This commit completes the migration to a fully module-driven architecture: ## Models Migration - Moved all domain models from models/database/ to their respective modules: - tenancy: User, Admin, Vendor, Company, Platform, VendorDomain, etc. - cms: MediaFile, VendorTheme - messaging: Email, VendorEmailSettings, VendorEmailTemplate - core: AdminMenuConfig - models/database/ now only contains Base and TimestampMixin (infrastructure) ## Schemas Migration - Moved all domain schemas from models/schema/ to their respective modules: - tenancy: company, vendor, admin, team, vendor_domain - cms: media, image, vendor_theme - messaging: email - models/schema/ now only contains base.py and auth.py (infrastructure) ## Routes Migration - Moved admin routes from app/api/v1/admin/ to modules: - menu_config.py -> core module - modules.py -> tenancy module - module_config.py -> tenancy module - app/api/v1/admin/ now only aggregates auto-discovered module routes ## Menu System - Implemented module-driven menu system with MenuDiscoveryService - Extended FrontendType enum: PLATFORM, ADMIN, VENDOR, STOREFRONT - Added MenuItemDefinition and MenuSectionDefinition dataclasses - Each module now defines its own menu items in definition.py - MenuService integrates with MenuDiscoveryService for template rendering ## Documentation - Updated docs/architecture/models-structure.md - Updated docs/architecture/menu-management.md - Updated architecture validation rules for new exceptions ## Architecture Validation - Updated MOD-019 rule to allow base.py in models/schema/ - Created core module exceptions.py and schemas/ directory - All validation errors resolved (only warnings remain) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
110 lines
3.9 KiB
Python
110 lines
3.9 KiB
Python
# app/modules/tenancy/models/company.py
|
|
"""
|
|
Company model representing the business entity that owns one or more vendor brands.
|
|
|
|
A Company represents the legal/business entity with contact information,
|
|
while Vendors represent the individual brands/storefronts operated by that company.
|
|
"""
|
|
|
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.core.database import Base
|
|
from models.database.base import TimestampMixin
|
|
|
|
|
|
class Company(Base, TimestampMixin):
|
|
"""
|
|
Represents a company (business entity) in the system.
|
|
|
|
A company owns one or more vendor brands. All business/contact information
|
|
is stored at the company level to avoid duplication.
|
|
"""
|
|
|
|
__tablename__ = "companies"
|
|
|
|
# ========================================================================
|
|
# Basic Information
|
|
# ========================================================================
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
"""Unique identifier for the company."""
|
|
|
|
name = Column(String, nullable=False, index=True)
|
|
"""Company legal/business name."""
|
|
|
|
description = Column(Text)
|
|
"""Optional description of the company."""
|
|
|
|
# ========================================================================
|
|
# Ownership
|
|
# ========================================================================
|
|
owner_user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
"""Foreign key to the user who owns this company."""
|
|
|
|
# ========================================================================
|
|
# Contact Information
|
|
# ========================================================================
|
|
contact_email = Column(String, nullable=False)
|
|
"""Primary business contact email."""
|
|
|
|
contact_phone = Column(String)
|
|
"""Business phone number."""
|
|
|
|
website = Column(String)
|
|
"""Company website URL."""
|
|
|
|
# ========================================================================
|
|
# Business Details
|
|
# ========================================================================
|
|
business_address = Column(Text)
|
|
"""Physical business address."""
|
|
|
|
tax_number = Column(String)
|
|
"""Tax/VAT registration number."""
|
|
|
|
# ========================================================================
|
|
# Status Flags
|
|
# ========================================================================
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
"""Whether the company is active. Affects all associated vendors."""
|
|
|
|
is_verified = Column(Boolean, default=False, nullable=False)
|
|
"""Whether the company has been verified by platform admins."""
|
|
|
|
# ========================================================================
|
|
# Relationships
|
|
# ========================================================================
|
|
owner = relationship("User", back_populates="owned_companies")
|
|
"""The user who owns this company."""
|
|
|
|
vendors = relationship(
|
|
"Vendor",
|
|
back_populates="company",
|
|
cascade="all, delete-orphan",
|
|
order_by="Vendor.name",
|
|
)
|
|
"""All vendor brands operated by this company."""
|
|
|
|
def __repr__(self):
|
|
"""String representation of the Company object."""
|
|
return f"<Company(id={self.id}, name='{self.name}', vendors={len(self.vendors) if self.vendors else 0})>"
|
|
|
|
# ========================================================================
|
|
# Helper Properties
|
|
# ========================================================================
|
|
|
|
@property
|
|
def vendor_count(self) -> int:
|
|
"""Get the number of vendors belonging to this company."""
|
|
return len(self.vendors) if self.vendors else 0
|
|
|
|
@property
|
|
def active_vendor_count(self) -> int:
|
|
"""Get the number of active vendors belonging to this company."""
|
|
if not self.vendors:
|
|
return 0
|
|
return sum(1 for v in self.vendors if v.is_active)
|
|
|
|
|
|
__all__ = ["Company"]
|