fix sequenst subscription and mandate
This commit is contained in:
parent
563018b5e1
commit
93f28f57df
1 changed files with 17 additions and 2 deletions
|
|
@ -1492,9 +1492,8 @@ class AppObjects:
|
|||
if not adminRoleId:
|
||||
raise ValueError(f"No admin role found for mandate {mandateId} — cannot assign user without role")
|
||||
|
||||
self.createUserMandate(userId, mandateId, roleIds=[adminRoleId], skipCapacityCheck=True)
|
||||
|
||||
from modules.interfaces.interfaceDbSubscription import _getRootInterface as _getSubRoot
|
||||
from modules.interfaces.interfaceDbBilling import _getRootInterface as _getBillingRoot
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
|
|
@ -1514,6 +1513,20 @@ class AppObjects:
|
|||
subInterface = _getSubRoot()
|
||||
subInterface.createSubscription(subscription)
|
||||
|
||||
try:
|
||||
billingRoot = _getBillingRoot()
|
||||
billingRoot.getOrCreateSettings(mandateId)
|
||||
billingRoot.ensureActivationBudget(mandateId, planKey)
|
||||
except Exception as billingEx:
|
||||
logger.error(
|
||||
"Initial billing setup failed for mandate %s (plan=%s): %s",
|
||||
mandateId,
|
||||
planKey,
|
||||
billingEx,
|
||||
)
|
||||
|
||||
self.createUserMandate(userId, mandateId, roleIds=[adminRoleId], skipCapacityCheck=True)
|
||||
|
||||
featureInterface = getFeatureInterface(self.db)
|
||||
mainModules = loadFeatureMainModules()
|
||||
createdInstances = []
|
||||
|
|
@ -1552,6 +1565,8 @@ class AppObjects:
|
|||
except Exception as e:
|
||||
logger.error(f"Error auto-creating instance for '{featureName}': {e}")
|
||||
|
||||
self._syncSubscriptionQuantity(mandateId)
|
||||
|
||||
logger.info(f"Provisioned mandate {mandateId} (plan={planKey}) for user {userId}, instances={createdInstances}")
|
||||
return {
|
||||
"mandateId": mandateId,
|
||||
|
|
|
|||
Loading…
Reference in a new issue