billing: Create get_current_plan_by_realm helper function.

This commit is contained in:
Vishnu KS
2020-03-24 18:52:27 +05:30
committed by Tim Abbott
parent 83da23c0d4
commit 8b24d40585
4 changed files with 35 additions and 19 deletions

View File

@@ -65,6 +65,12 @@ def get_current_plan_by_customer(customer: Customer) -> Optional[CustomerPlan]:
return CustomerPlan.objects.filter(
customer=customer, status__lt=CustomerPlan.LIVE_STATUS_THRESHOLD).first()
def get_current_plan_by_realm(realm: Realm) -> Optional[CustomerPlan]:
customer = get_customer_by_realm(realm)
if customer is None:
return None
return get_current_plan_by_customer(customer)
class LicenseLedger(models.Model):
plan = models.ForeignKey(CustomerPlan, on_delete=CASCADE) # type: CustomerPlan
# Also True for the initial upgrade.