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

@@ -369,11 +369,10 @@ def get_platform_email_config(db: Session) -> dict:
Returns:
Dictionary with all email configuration values
"""
from app.modules.tenancy.models import AdminSetting
from app.modules.core.services.admin_settings_service import admin_settings_service
def get_db_setting(key: str) -> str | None:
setting = db.query(AdminSetting).filter(AdminSetting.key == key).first()
return setting.value if setting else None
return admin_settings_service.get_setting_value(db, key)
config = {}
@@ -999,10 +998,10 @@ class EmailService:
def _get_store(self, store_id: int):
"""Get store with caching."""
if store_id not in self._store_cache:
from app.modules.tenancy.models import Store
from app.modules.tenancy.services.store_service import store_service
self._store_cache[store_id] = (
self.db.query(Store).filter(Store.id == store_id).first()
self._store_cache[store_id] = store_service.get_store_by_id_optional(
self.db, store_id
)
return self._store_cache[store_id]
@@ -1121,11 +1120,9 @@ class EmailService:
# 2. Customer's preferred language
if customer_id:
from app.modules.customers.models.customer import Customer
from app.modules.customers.services.customer_service import customer_service
customer = (
self.db.query(Customer).filter(Customer.id == customer_id).first()
)
customer = customer_service.get_customer_by_id(self.db, customer_id)
if customer and customer.preferred_language in SUPPORTED_LANGUAGES:
return customer.preferred_language