refactor(arch): eliminate all cross-module model imports in service layer
Some checks failed
CI / ruff (push) Successful in 9s
CI / docs (push) Has been cancelled
CI / deploy (push) Has been cancelled
CI / validate (push) Has been cancelled
CI / dependency-scanning (push) Has been cancelled
CI / pytest (push) Has been cancelled

Enforce MOD-025/MOD-026 rules: zero top-level cross-module model imports
remain in any service file. All 66 files migrated using deferred import
patterns (method-body, _get_model() helpers, instance-cached self._Model)
and new cross-module service methods in tenancy. Documentation updated
with Pattern 6 (deferred imports), migration plan marked complete, and
violations status reflects 84→0 service-layer violations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 06:13:15 +01:00
parent e3a52f6536
commit 86e85a98b8
66 changed files with 2242 additions and 1295 deletions

View File

@@ -31,7 +31,6 @@ from app.modules.marketplace.services.letzshop import (
LetzshopOrderService,
)
from app.modules.tenancy.exceptions import StoreNotFoundException
from app.modules.tenancy.models import Store
logger = logging.getLogger(__name__)
@@ -52,6 +51,12 @@ class OnboardingService:
"""
self.db = db
def _get_store(self, store_id: int):
"""Get store by ID via store service."""
from app.modules.tenancy.services.store_service import store_service
return store_service.get_store_by_id_optional(self.db, store_id)
# =========================================================================
# Onboarding CRUD
# =========================================================================
@@ -167,7 +172,7 @@ class OnboardingService:
def get_merchant_profile_data(self, store_id: int) -> dict:
"""Get current merchant profile data for editing."""
store = self.db.query(Store).filter(Store.id == store_id).first()
store = self._get_store(store_id)
if not store:
return {}
@@ -206,7 +211,7 @@ class OnboardingService:
Returns response with next step information.
"""
# Check store exists BEFORE creating onboarding record (FK constraint)
store = self.db.query(Store).filter(Store.id == store_id).first()
store = self._get_store(store_id)
if not store:
raise StoreNotFoundException(store_id)
@@ -346,7 +351,7 @@ class OnboardingService:
)
# Update store with Letzshop identity
store = self.db.query(Store).filter(Store.id == store_id).first()
store = self._get_store(store_id)
if store:
store.letzshop_store_slug = shop_slug
if letzshop_store_id:
@@ -374,7 +379,7 @@ class OnboardingService:
def get_product_import_config(self, store_id: int) -> dict:
"""Get current product import configuration."""
store = self.db.query(Store).filter(Store.id == store_id).first()
store = self._get_store(store_id)
if not store:
return {}
@@ -422,7 +427,7 @@ class OnboardingService:
raise OnboardingCsvUrlRequiredException()
# Update store settings
store = self.db.query(Store).filter(Store.id == store_id).first()
store = self._get_store(store_id)
if not store:
raise StoreNotFoundException(store_id)
@@ -607,7 +612,7 @@ class OnboardingService:
self.db.flush()
# Get store code for redirect URL
store = self.db.query(Store).filter(Store.id == store_id).first()
store = self._get_store(store_id)
store_code = store.store_code if store else ""
logger.info(f"Completed onboarding for store {store_id}")