Complete Implemenation of tenancy

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-09 00:11:35 +00:00
parent c54db6c2d9
commit bfbade7624
25 changed files with 4959 additions and 35 deletions

View File

@@ -124,6 +124,21 @@ class Account(SoftDeletableModel):
def __str__(self):
return self.name
@property
def default_payment_method(self):
"""Get default payment method from AccountPaymentMethod table"""
try:
from igny8_core.business.billing.models import AccountPaymentMethod
method = AccountPaymentMethod.objects.filter(
account=self,
is_default=True,
is_enabled=True
).first()
return method.type if method else self.payment_method
except Exception:
# Fallback to field if table doesn't exist or error
return self.payment_method
def is_system_account(self):
"""Check if this account is a system account with highest access level."""
# System accounts bypass all filtering restrictions
@@ -230,6 +245,14 @@ class Subscription(models.Model):
]
account = models.OneToOneField('igny8_core_auth.Account', on_delete=models.CASCADE, related_name='subscription', db_column='tenant_id')
plan = models.ForeignKey(
'igny8_core_auth.Plan',
on_delete=models.PROTECT,
related_name='subscriptions',
null=True,
blank=True,
help_text='Subscription plan (tracks historical plan even if account changes plan)'
)
stripe_subscription_id = models.CharField(
max_length=255,
blank=True,
@@ -237,12 +260,6 @@ class Subscription(models.Model):
db_index=True,
help_text='Stripe subscription ID (when using Stripe)'
)
payment_method = models.CharField(
max_length=30,
choices=PAYMENT_METHOD_CHOICES,
default='stripe',
help_text='Payment method for this subscription'
)
external_payment_id = models.CharField(
max_length=255,
blank=True,
@@ -255,6 +272,14 @@ class Subscription(models.Model):
cancel_at_period_end = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@property
def payment_method(self):
"""Get payment method from account's default payment method"""
if hasattr(self.account, 'default_payment_method'):
return self.account.default_payment_method
# Fallback to account.payment_method field if property doesn't exist yet
return getattr(self.account, 'payment_method', 'stripe')
class Meta:
db_table = 'igny8_subscriptions'
@@ -286,9 +311,7 @@ class Site(SoftDeletableModel, AccountBaseModel):
'igny8_core_auth.Industry',
on_delete=models.PROTECT,
related_name='sites',
null=True,
blank=True,
help_text="Industry this site belongs to"
help_text="Industry this site belongs to (required for sector creation)"
)
is_active = models.BooleanField(default=True, db_index=True)
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='active')