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

@@ -10,7 +10,10 @@ Provides:
- Webhook event construction
"""
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
import stripe
from sqlalchemy.orm import Session
@@ -23,7 +26,9 @@ from app.modules.billing.exceptions import (
from app.modules.billing.models import (
MerchantSubscription,
)
from app.modules.tenancy.models import Store
if TYPE_CHECKING:
from app.modules.tenancy.models import Store
logger = logging.getLogger(__name__)
@@ -294,10 +299,10 @@ class StripeService:
self._check_configured()
# Get or create Stripe customer
from app.modules.tenancy.models import StorePlatform
from app.modules.tenancy.services.platform_service import platform_service
from app.modules.tenancy.services.team_service import team_service
sp = db.query(StorePlatform.platform_id).filter(StorePlatform.store_id == store.id).first()
platform_id = sp[0] if sp else None
platform_id = platform_service.get_primary_platform_id_for_store(db, store.id)
subscription = None
if store.merchant_id and platform_id:
subscription = (
@@ -313,16 +318,7 @@ class StripeService:
customer_id = subscription.stripe_customer_id
else:
# Get store owner email
from app.modules.tenancy.models import StoreUser
owner = (
db.query(StoreUser)
.filter(
StoreUser.store_id == store.id,
StoreUser.is_owner == True,
)
.first()
)
owner = team_service.get_store_owner(db, store.id)
email = owner.user.email if owner and owner.user else None
customer_id = self.create_customer(store, email or f"{store.store_code}@placeholder.com")