P0 HOTFIX: Subscription asset_limit calculation fix
Root cause: Old code used rules.get('max_vehicles') which only searched
JSONB root level. Corporate tiers store limits under rules['allowances'].
Changes:
1. Added _extract_limit() helper (3-level search: direct → allowances → limits)
2. Replaced single-sub .limit(1) with multi-sub .all() for true aggregation
3. Fixed fallback path to use _extract_limit() instead of rules.get()
4. Added clamping: asset_limit = max(asset_limit, 1) right before
SubscriptionSummary creation on BOTH code paths
5. Added 'type' column to SubscriptionTier model (base vs addon)
This commit is contained in:
@@ -69,6 +69,10 @@ class SubscriptionTier(Base):
|
||||
"""
|
||||
Előfizetési csomagok definíciója (pl. Free, Premium, VIP).
|
||||
A csomagok határozzák meg a korlátokat (pl. max járműszám).
|
||||
|
||||
P0 MULTI-SUBSCRIPTION AGGREGATION:
|
||||
A `type` mező különbözteti meg a Base tier-eket ('private', 'corporate', 'business')
|
||||
az Add-on tier-ektől ('addon'). Ez lehetővé teszi az "1 Base + N Add-on" modellt.
|
||||
"""
|
||||
__tablename__ = "subscription_tiers"
|
||||
__table_args__ = {"schema": "system"}
|
||||
@@ -78,6 +82,18 @@ class SubscriptionTier(Base):
|
||||
rules: Mapped[dict] = mapped_column(JSONB, server_default=text("'{}'::jsonb")) # pl. {"max_vehicles": 5}
|
||||
is_custom: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
# ── P0 MULTI-SUBSCRIPTION AGGREGATION: Base vs Add-on típus ──
|
||||
# 'base' = core tier (individual, corporate, business)
|
||||
# 'addon' = add-on tier (extra vehicles, branches, users)
|
||||
# None/empty = treated as 'base' for backward compatibility
|
||||
type: Mapped[Optional[str]] = mapped_column(
|
||||
String(20),
|
||||
nullable=True,
|
||||
default=None,
|
||||
server_default=text("NULL"),
|
||||
comment="Tier type: 'base' for core subscriptions, 'addon' for add-on tiers. NULL = base (backward compat)."
|
||||
)
|
||||
|
||||
# ── P0 3D CAPABILITY MATRIX: feature_capabilities JSONB ──
|
||||
# Defines what features/capabilities this subscription tier unlocks.
|
||||
# Example: {"can_export_data": True, "can_use_analytics": True, "max_vehicles": 50}
|
||||
|
||||
Reference in New Issue
Block a user