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

@@ -14,12 +14,10 @@ and feature_service for limit resolution.
import logging
from dataclasses import dataclass
from sqlalchemy import func
from sqlalchemy.orm import Session
from app.modules.billing.models import MerchantSubscription, SubscriptionTier
from app.modules.billing.services.feature_aggregator import feature_aggregator
from app.modules.tenancy.models import StoreUser
logger = logging.getLogger(__name__)
@@ -222,12 +220,9 @@ class UsageService:
def _get_team_member_count(self, db: Session, store_id: int) -> int:
"""Get active team member count for store."""
return (
db.query(func.count(StoreUser.id))
.filter(StoreUser.store_id == store_id, StoreUser.is_active == True) # noqa: E712
.scalar()
or 0
)
from app.modules.tenancy.services.team_service import team_service
return team_service.get_active_team_member_count(db, store_id)
def _calculate_usage_metrics(
self, db: Session, store_id: int, subscription: MerchantSubscription | None