(self, new_plan_version, date_end=None,
                    note=None, web_user=None, adjustment_method=None,
                    service_type=None, pro_bono_status=None, funding_source=None,
                    transfer_credits=True, internal_change=False, account=None,
                    do_not_invoice=None, no_invoice_reason=None,
                    auto_generate_credits=False, is_trial=False)
return new_subscription
Changing a plan TERMINATES the current subscription and
        creates a NEW SUBSCRIPTION where the old plan left off.
        This is not the same thing as simply updating the subscription.

        date_end is a date in the future and only applies to the NEW
        subscription. The current subscription will always end immediately
        (today) and the date_start of the new subscription will always be today.
Changing a plan TERMINATES the current subscription and
        creates a NEW SUBSCRIPTION where the old plan left off.
        This is not the same thing as simply updating the subscription.
Changing a plan TERMINATES the current subscription and creates a NEW SUBSCRIPTION where the old plan left off . This is not the same thing as simply updating the subscription .
def change_plan(self, new_plan_version, date_end=None,
                    note=None, web_user=None, adjustment_method=None,
                    service_type=None, pro_bono_status=None, funding_source=None,
                    transfer_credits=True, internal_change=False, account=None,
                    do_not_invoice=None, no_invoice_reason=None,
                    auto_generate_credits=False, is_trial=False):
        """
        Changing a plan TERMINATES the current subscription and
        creates a NEW SUBSCRIPTION where the old plan left off.
        This is not the same thing as simply updating the subscription.

        date_end is a date in the future and only applies to the NEW
        subscription. The current subscription will always end immediately
        (today) and the date_start of the new subscription will always be today.
        """
        from corehq.apps.analytics.tasks import track_workflow
        adjustment_method = adjustment_method or SubscriptionAdjustmentMethod.INTERNAL

        today = datetime.date.today()
        assert self.is_active
        assert date_end is None or date_end >= today

        if new_plan_version.plan.at_max_domains() and self.plan_version.plan != new_plan_version.plan:
            raise SubscriptionAdjustmentError(
                'The maximum number of project spaces has been reached for %(new_plan_version)s. ' % {
                    'new_plan_version': new_plan_version,
                }
            )

        self.date_end = today
        self.is_active = False
        self.save()

        new_subscription = Subscription(
            account=account if account else self.account,
            plan_version=new_plan_version,
            subscriber=self.subscriber,
            salesforce_contract_id=self.salesforce_contract_id,
            date_start=today,
            date_end=date_end,
            is_active=True,
            do_not_invoice=do_not_invoice if do_not_invoice is not None else self.do_not_invoice,
            no_invoice_reason=no_invoice_reason if no_invoice_reason is not None else self.no_invoice_reason,
            auto_generate_credits=auto_generate_credits,
            is_trial=is_trial,
            service_type=(service_type or SubscriptionType.NOT_SET),
            pro_bono_status=(pro_bono_status or ProBonoStatus.NO),
            funding_source=(funding_source or FundingSource.CLIENT),
            skip_auto_downgrade=False,
            skip_auto_downgrade_reason='',
        )

        new_subscription.save()
        new_subscription.raise_conflicting_dates(new_subscription.date_start, new_subscription.date_end)

        new_subscription.set_billing_account_entry_point()

        change_status_result = get_change_status(self.plan_version, new_plan_version)
        self.subscriber.change_subscription(
            downgraded_privileges=change_status_result.downgraded_privs,
            upgraded_privileges=change_status_result.upgraded_privs,
            new_plan_version=new_plan_version,
            old_subscription=self,
            new_subscription=new_subscription,
            internal_change=internal_change,
        )

        # transfer existing credit lines to the new subscription
        if transfer_credits:
            self.transfer_credits(new_subscription)

        # record transfer from old subscription
        SubscriptionAdjustment.record_adjustment(
            self, method=adjustment_method, note=note, web_user=web_user,
            reason=change_status_result.adjustment_reason, related_subscription=new_subscription
        )
        SubscriptionAdjustment.record_adjustment(
            new_subscription, method=adjustment_method, note=note, web_user=web_user,
            reason=SubscriptionAdjustmentReason.CREATE
        )

        upgrade_reasons = [SubscriptionAdjustmentReason.UPGRADE, SubscriptionAdjustmentReason.CREATE]
        if web_user and adjustment_method == SubscriptionAdjustmentMethod.USER:
            if change_status_result.adjustment_reason in upgrade_reasons:
                track_workflow(web_user, 'Changed Plan: Upgrade')
            if change_status_result.adjustment_reason == SubscriptionAdjustmentReason.DOWNGRADE:
                track_workflow(web_user, 'Changed Plan: Downgrade')

        return new_subscription
def change_plan ( self , new_plan_version , date_end = None , note = None , web_user = None , adjustment_method = None , service_type = None , pro_bono_status = None , funding_source = None , transfer_credits = True , internal_change = False , account = None , do_not_invoice = None , no_invoice_reason = None , auto_generate_credits = False , is_trial = False ) : from corehq . apps . analytics . tasks import track_workflow adjustment_method = adjustment_method or SubscriptionAdjustmentMethod . INTERNAL today = datetime . date . today ( ) assert self . is_active assert date_end is None or date_end >= today if new_plan_version . plan . at_max_domains ( ) and self . plan_version . plan != new_plan_version . plan : raise SubscriptionAdjustmentError ( 'The maximum number of project spaces has been reached for %(new_plan_version)s. ' % { 'new_plan_version' : new_plan_version , } ) self . date_end = today self . is_active = False self . save ( ) new_subscription = Subscription ( account = account if account else self . account , plan_version = new_plan_version , subscriber = self . subscriber , salesforce_contract_id = self . salesforce_contract_id , date_start = today , date_end = date_end , is_active = True , do_not_invoice = do_not_invoice if do_not_invoice is not None else self . do_not_invoice , no_invoice_reason = no_invoice_reason if no_invoice_reason is not None else self . no_invoice_reason , auto_generate_credits = auto_generate_credits , is_trial = is_trial , service_type = ( service_type or SubscriptionType . NOT_SET ) , pro_bono_status = ( pro_bono_status or ProBonoStatus . NO ) , funding_source = ( funding_source or FundingSource . CLIENT ) , skip_auto_downgrade = False , skip_auto_downgrade_reason = '' , ) new_subscription . save ( ) new_subscription . raise_conflicting_dates ( new_subscription . date_start , new_subscription . date_end ) new_subscription . set_billing_account_entry_point ( ) change_status_result = get_change_status ( self . plan_version , new_plan_version ) self . subscriber . change_subscription ( downgraded_privileges = change_status_result . downgraded_privs , upgraded_privileges = change_status_result . upgraded_privs , new_plan_version = new_plan_version , old_subscription = self , new_subscription = new_subscription , internal_change = internal_change , ) # transfer existing credit lines to the new subscription if transfer_credits : self . transfer_credits ( new_subscription ) # record transfer from old subscription SubscriptionAdjustment . record_adjustment ( self , method = adjustment_method , note = note , web_user = web_user , reason = change_status_result . adjustment_reason , related_subscription = new_subscription ) SubscriptionAdjustment . record_adjustment ( new_subscription , method = adjustment_method , note = note , web_user = web_user , reason = SubscriptionAdjustmentReason . CREATE ) upgrade_reasons = [ SubscriptionAdjustmentReason . UPGRADE , SubscriptionAdjustmentReason . CREATE ] if web_user and adjustment_method == SubscriptionAdjustmentMethod . USER : if change_status_result . adjustment_reason in upgrade_reasons : track_workflow ( web_user , 'Changed Plan: Upgrade' ) if change_status_result . adjustment_reason == SubscriptionAdjustmentReason . DOWNGRADE : track_workflow ( web_user , 'Changed Plan: Downgrade' ) return new_subscription