feat: extract inventory, orders, and marketplace modules (Phase 4)

Extract three additional modules following the billing module pattern:

Inventory Module (app/modules/inventory/):
- Stock management and tracking
- Inventory locations
- Low stock alerts
- Admin and vendor routes with module access control

Orders Module (app/modules/orders/):
- Order management and fulfillment
- Order item exceptions
- Bulk operations and export
- Admin and vendor routes with module access control

Marketplace Module (app/modules/marketplace/):
- Letzshop integration
- Product sync
- Marketplace import
- Depends on inventory module
- Admin and vendor routes with module access control

Admin router updated:
- Uses module routers with require_module_access dependency
- Legacy router includes commented out
- Routes verified: 15 inventory, 16 orders, 42 marketplace

All 31 module tests passing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-25 22:02:24 +01:00
parent c614b7d74c
commit 9d0dc51de0
17 changed files with 559 additions and 83 deletions

View File

@@ -0,0 +1,25 @@
# app/modules/marketplace/__init__.py
"""
Marketplace Module - Letzshop integration.
This module provides:
- Letzshop product sync
- Marketplace import operations
- Product catalog synchronization
- Order import from marketplace
Dependencies:
- Requires: inventory module (for product management)
Routes:
- Admin: /api/v1/admin/marketplace/*, /api/v1/admin/letzshop/*
- Vendor: /api/v1/vendor/marketplace/*, /api/v1/vendor/letzshop/*
Menu Items:
- Admin: marketplace-letzshop
- Vendor: marketplace, letzshop
"""
from app.modules.marketplace.definition import marketplace_module
__all__ = ["marketplace_module"]

View File

@@ -0,0 +1,70 @@
# app/modules/marketplace/definition.py
"""
Marketplace module definition.
Defines the marketplace module including its features, menu items,
dependencies, and route configurations.
Note: This module requires the inventory module to be enabled.
"""
from app.modules.base import ModuleDefinition
from models.database.admin_menu_config import FrontendType
def _get_admin_router():
"""Lazy import of admin router to avoid circular imports."""
from app.modules.marketplace.routes.admin import admin_router
return admin_router
def _get_vendor_router():
"""Lazy import of vendor router to avoid circular imports."""
from app.modules.marketplace.routes.vendor import vendor_router
return vendor_router
# Marketplace module definition
marketplace_module = ModuleDefinition(
code="marketplace",
name="Marketplace (Letzshop)",
description=(
"Letzshop marketplace integration for product sync, order import, "
"and catalog synchronization."
),
requires=["inventory"], # Depends on inventory module
features=[
"letzshop_sync", # Sync products with Letzshop
"marketplace_import", # Import products from marketplace
"product_sync", # Bidirectional product sync
"order_import", # Import orders from marketplace
"marketplace_analytics", # Marketplace performance metrics
],
menu_items={
FrontendType.ADMIN: [
"marketplace-letzshop", # Marketplace monitoring
],
FrontendType.VENDOR: [
"marketplace", # Vendor marketplace settings
"letzshop", # Letzshop integration
],
},
is_core=False,
)
def get_marketplace_module_with_routers() -> ModuleDefinition:
"""
Get marketplace module with routers attached.
This function attaches the routers lazily to avoid circular imports
during module initialization.
"""
marketplace_module.admin_router = _get_admin_router()
marketplace_module.vendor_router = _get_vendor_router()
return marketplace_module
__all__ = ["marketplace_module", "get_marketplace_module_with_routers"]

View File

@@ -0,0 +1,12 @@
# app/modules/marketplace/routes/__init__.py
"""
Marketplace module route registration.
This module provides functions to register marketplace routes
with module-based access control.
"""
from app.modules.marketplace.routes.admin import admin_router, admin_letzshop_router
from app.modules.marketplace.routes.vendor import vendor_router, vendor_letzshop_router
__all__ = ["admin_router", "admin_letzshop_router", "vendor_router", "vendor_letzshop_router"]

View File

@@ -0,0 +1,39 @@
# app/modules/marketplace/routes/admin.py
"""
Marketplace module admin routes.
This module wraps the existing admin marketplace routes and adds
module-based access control. Routes are re-exported from the
original location with the module access dependency.
Includes:
- /marketplace/* - Marketplace monitoring
- /letzshop/* - Letzshop integration
"""
from fastapi import APIRouter, Depends
from app.api.deps import require_module_access
# Import original routers
from app.api.v1.admin import marketplace as marketplace_routes
from app.api.v1.admin import letzshop as letzshop_routes
# Create module-aware router for marketplace
admin_router = APIRouter(
prefix="/marketplace",
dependencies=[Depends(require_module_access("marketplace"))],
)
# Re-export all routes from the original marketplace module
for route in marketplace_routes.router.routes:
admin_router.routes.append(route)
# Create separate router for letzshop integration
admin_letzshop_router = APIRouter(
prefix="/letzshop",
dependencies=[Depends(require_module_access("marketplace"))],
)
for route in letzshop_routes.router.routes:
admin_letzshop_router.routes.append(route)

View File

@@ -0,0 +1,39 @@
# app/modules/marketplace/routes/vendor.py
"""
Marketplace module vendor routes.
This module wraps the existing vendor marketplace routes and adds
module-based access control. Routes are re-exported from the
original location with the module access dependency.
Includes:
- /marketplace/* - Marketplace settings
- /letzshop/* - Letzshop integration
"""
from fastapi import APIRouter, Depends
from app.api.deps import require_module_access
# Import original routers
from app.api.v1.vendor import marketplace as marketplace_routes
from app.api.v1.vendor import letzshop as letzshop_routes
# Create module-aware router for marketplace
vendor_router = APIRouter(
prefix="/marketplace",
dependencies=[Depends(require_module_access("marketplace"))],
)
# Re-export all routes from the original marketplace module
for route in marketplace_routes.router.routes:
vendor_router.routes.append(route)
# Create separate router for letzshop integration
vendor_letzshop_router = APIRouter(
prefix="/letzshop",
dependencies=[Depends(require_module_access("marketplace"))],
)
for route in letzshop_routes.router.routes:
vendor_letzshop_router.routes.append(route)