fix(subscriptions): fix subscription UI and API after store→merchant migration
Store detail page now shows all platform subscriptions instead of always "No Subscription Found". Subscriptions listing page renamed from Store to Merchant throughout (template, JS, menu, i18n) with Platform column added. Tiers API supports platform_id filtering. Merchant detail page no longer hardcodes 'oms' platform — loads all platforms, shows subscription cards per platform with labels, and the Create Subscription modal includes a platform selector with platform-filtered tiers. Create button always accessible in Quick Actions. Edit modal on /admin/subscriptions loads tiers from API filtered by platform instead of hardcoded options, sends tier_code (not tier) to match PATCH schema, and shows platform context. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,14 +40,20 @@ class AdminSubscriptionService:
|
||||
# =========================================================================
|
||||
|
||||
def get_tiers(
|
||||
self, db: Session, include_inactive: bool = False
|
||||
self, db: Session, include_inactive: bool = False, platform_id: int | None = None
|
||||
) -> list[SubscriptionTier]:
|
||||
"""Get all subscription tiers."""
|
||||
"""Get all subscription tiers, optionally filtered by platform."""
|
||||
query = db.query(SubscriptionTier)
|
||||
|
||||
if not include_inactive:
|
||||
query = query.filter(SubscriptionTier.is_active == True) # noqa: E712
|
||||
|
||||
if platform_id is not None:
|
||||
query = query.filter(
|
||||
(SubscriptionTier.platform_id == platform_id)
|
||||
| (SubscriptionTier.platform_id.is_(None))
|
||||
)
|
||||
|
||||
return query.order_by(SubscriptionTier.display_order).all()
|
||||
|
||||
def get_tier_by_code(self, db: Session, tier_code: str) -> SubscriptionTier:
|
||||
|
||||
@@ -115,27 +115,48 @@ class FeatureService:
|
||||
Returns:
|
||||
Tuple of (merchant_id, platform_id), either may be None
|
||||
"""
|
||||
from app.modules.tenancy.models import Store
|
||||
from app.modules.tenancy.models import Store, StorePlatform
|
||||
|
||||
store = db.query(Store).filter(Store.id == store_id).first()
|
||||
if not store:
|
||||
return None, None
|
||||
|
||||
merchant_id = store.merchant_id
|
||||
# Get platform_id from store's platform association
|
||||
platform_id = getattr(store, "platform_id", None)
|
||||
if platform_id is None:
|
||||
# Try StorePlatform junction
|
||||
from app.modules.tenancy.models import StorePlatform
|
||||
sp = (
|
||||
db.query(StorePlatform.platform_id)
|
||||
.filter(StorePlatform.store_id == store_id)
|
||||
.first()
|
||||
)
|
||||
platform_id = sp[0] if sp else None
|
||||
# Get primary platform_id from StorePlatform junction
|
||||
sp = (
|
||||
db.query(StorePlatform.platform_id)
|
||||
.filter(StorePlatform.store_id == store_id, StorePlatform.is_active == True) # noqa: E712
|
||||
.order_by(StorePlatform.is_primary.desc())
|
||||
.first()
|
||||
)
|
||||
platform_id = sp[0] if sp else None
|
||||
|
||||
return merchant_id, platform_id
|
||||
|
||||
def _get_merchant_and_platforms_for_store(
|
||||
self, db: Session, store_id: int
|
||||
) -> tuple[int | None, list[int]]:
|
||||
"""
|
||||
Resolve store_id to (merchant_id, [platform_ids]).
|
||||
|
||||
Returns all active platform IDs for the store's merchant,
|
||||
ordered with the primary platform first.
|
||||
"""
|
||||
from app.modules.tenancy.models import Store, StorePlatform
|
||||
|
||||
store = db.query(Store).filter(Store.id == store_id).first()
|
||||
if not store:
|
||||
return None, []
|
||||
|
||||
platform_ids = [
|
||||
sp[0]
|
||||
for sp in db.query(StorePlatform.platform_id)
|
||||
.filter(StorePlatform.store_id == store_id, StorePlatform.is_active == True) # noqa: E712
|
||||
.order_by(StorePlatform.is_primary.desc())
|
||||
.all()
|
||||
]
|
||||
return store.merchant_id, platform_ids
|
||||
|
||||
def _get_subscription(
|
||||
self, db: Session, merchant_id: int, platform_id: int
|
||||
) -> MerchantSubscription | None:
|
||||
|
||||
Reference in New Issue
Block a user