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

@@ -143,18 +143,20 @@ class OrderFeatureProvider:
platform_id: int,
) -> list[FeatureUsage]:
from app.modules.orders.models.order import Order
from app.modules.tenancy.models import Store, StorePlatform
from app.modules.tenancy.services.platform_service import platform_service
from app.modules.tenancy.services.store_service import store_service
now = datetime.now(UTC)
period_start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
merchant_stores = store_service.get_stores_by_merchant_id(db, merchant_id)
platform_store_ids = platform_service.get_store_ids_for_platform(db, platform_id)
store_ids = [s.id for s in merchant_stores if s.id in platform_store_ids]
count = (
db.query(func.count(Order.id))
.join(Store, Order.store_id == Store.id)
.join(StorePlatform, Store.id == StorePlatform.store_id)
.filter(
Store.merchant_id == merchant_id,
StorePlatform.platform_id == platform_id,
Order.store_id.in_(store_ids),
Order.created_at >= period_start,
)
.scalar()