From 93f28f57df1910efe6bf92819995eed1c68b26a4 Mon Sep 17 00:00:00 2001
From: ValueOn AG
Date: Thu, 2 Apr 2026 11:58:34 +0200
Subject: [PATCH] fix sequenst subscription and mandate
---
modules/interfaces/interfaceDbApp.py | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/modules/interfaces/interfaceDbApp.py b/modules/interfaces/interfaceDbApp.py
index 01863b41..5e346a86 100644
--- a/modules/interfaces/interfaceDbApp.py
+++ b/modules/interfaces/interfaceDbApp.py
@@ -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,