mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	billing: Create is_free_trial function in CustomerPlan model.
This commit is contained in:
		@@ -136,7 +136,7 @@ def next_month(billing_cycle_anchor: datetime, dt: datetime) -> datetime:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def start_of_next_billing_cycle(plan: CustomerPlan, event_time: datetime) -> datetime:
 | 
					def start_of_next_billing_cycle(plan: CustomerPlan, event_time: datetime) -> datetime:
 | 
				
			||||||
    if plan.status == CustomerPlan.FREE_TRIAL:
 | 
					    if plan.is_free_trial():
 | 
				
			||||||
        assert plan.next_invoice_date is not None  # for mypy
 | 
					        assert plan.next_invoice_date is not None  # for mypy
 | 
				
			||||||
        return plan.next_invoice_date
 | 
					        return plan.next_invoice_date
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -358,7 +358,7 @@ def make_end_of_cycle_updates_if_needed(
 | 
				
			|||||||
                licenses=last_ledger_entry.licenses_at_next_renewal,
 | 
					                licenses=last_ledger_entry.licenses_at_next_renewal,
 | 
				
			||||||
                licenses_at_next_renewal=last_ledger_entry.licenses_at_next_renewal,
 | 
					                licenses_at_next_renewal=last_ledger_entry.licenses_at_next_renewal,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
        if plan.status == CustomerPlan.FREE_TRIAL:
 | 
					        if plan.is_free_trial():
 | 
				
			||||||
            plan.invoiced_through = last_ledger_entry
 | 
					            plan.invoiced_through = last_ledger_entry
 | 
				
			||||||
            assert plan.next_invoice_date is not None
 | 
					            assert plan.next_invoice_date is not None
 | 
				
			||||||
            plan.billing_cycle_anchor = plan.next_invoice_date.replace(microsecond=0)
 | 
					            plan.billing_cycle_anchor = plan.next_invoice_date.replace(microsecond=0)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -117,6 +117,9 @@ class CustomerPlan(models.Model):
 | 
				
			|||||||
            LicenseLedger.objects.filter(plan=self).order_by("id").last().licenses_at_next_renewal
 | 
					            LicenseLedger.objects.filter(plan=self).order_by("id").last().licenses_at_next_renewal
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def is_free_trial(self) -> bool:
 | 
				
			||||||
 | 
					        return self.status == CustomerPlan.FREE_TRIAL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_current_plan_by_customer(customer: Customer) -> Optional[CustomerPlan]:
 | 
					def get_current_plan_by_customer(customer: Customer) -> Optional[CustomerPlan]:
 | 
				
			||||||
    return CustomerPlan.objects.filter(
 | 
					    return CustomerPlan.objects.filter(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -300,7 +300,6 @@ def billing_home(request: HttpRequest) -> HttpResponse:
 | 
				
			|||||||
            if new_plan is not None:  # nocoverage
 | 
					            if new_plan is not None:  # nocoverage
 | 
				
			||||||
                plan = new_plan
 | 
					                plan = new_plan
 | 
				
			||||||
            assert plan is not None  # for mypy
 | 
					            assert plan is not None  # for mypy
 | 
				
			||||||
            free_trial = plan.status == CustomerPlan.FREE_TRIAL
 | 
					 | 
				
			||||||
            downgrade_at_end_of_cycle = plan.status == CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE
 | 
					            downgrade_at_end_of_cycle = plan.status == CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE
 | 
				
			||||||
            switch_to_annual_at_end_of_cycle = (
 | 
					            switch_to_annual_at_end_of_cycle = (
 | 
				
			||||||
                plan.status == CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE
 | 
					                plan.status == CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE
 | 
				
			||||||
@@ -324,7 +323,7 @@ def billing_home(request: HttpRequest) -> HttpResponse:
 | 
				
			|||||||
            context.update(
 | 
					            context.update(
 | 
				
			||||||
                plan_name=plan.name,
 | 
					                plan_name=plan.name,
 | 
				
			||||||
                has_active_plan=True,
 | 
					                has_active_plan=True,
 | 
				
			||||||
                free_trial=free_trial,
 | 
					                free_trial=plan.is_free_trial(),
 | 
				
			||||||
                downgrade_at_end_of_cycle=downgrade_at_end_of_cycle,
 | 
					                downgrade_at_end_of_cycle=downgrade_at_end_of_cycle,
 | 
				
			||||||
                automanage_licenses=plan.automanage_licenses,
 | 
					                automanage_licenses=plan.automanage_licenses,
 | 
				
			||||||
                switch_to_annual_at_end_of_cycle=switch_to_annual_at_end_of_cycle,
 | 
					                switch_to_annual_at_end_of_cycle=switch_to_annual_at_end_of_cycle,
 | 
				
			||||||
@@ -391,7 +390,7 @@ def update_plan(
 | 
				
			|||||||
            assert plan.fixed_price is None
 | 
					            assert plan.fixed_price is None
 | 
				
			||||||
            do_change_plan_status(plan, status)
 | 
					            do_change_plan_status(plan, status)
 | 
				
			||||||
        elif status == CustomerPlan.ENDED:
 | 
					        elif status == CustomerPlan.ENDED:
 | 
				
			||||||
            assert plan.status == CustomerPlan.FREE_TRIAL
 | 
					            assert plan.is_free_trial()
 | 
				
			||||||
            downgrade_now_without_creating_additional_invoices(user.realm)
 | 
					            downgrade_now_without_creating_additional_invoices(user.realm)
 | 
				
			||||||
        return json_success()
 | 
					        return json_success()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user