Esempio n. 1
0
def fill_billing_log_billed_up_to_fields(apps, schema_editor):
    # this tries to fill a subscription's billinglogs plan_billed_up_to and
    # metered_features_billed_up_to fields with somewhat sane values

    BillingLog = apps.get_model('silver', 'BillingLog')
    db_alias = schema_editor.connection.alias

    for billing_log in BillingLog.objects.using(db_alias).all():
        subscription = billing_log.subscription
        billing_date = billing_log.billing_date

        plan_billed_up_to = last_day_of_month(billing_date)
        metered_features_billed_up_to = last_day_of_month(
            prev_month(billing_date))

        if subscription.trial_end:
            if billing_date == subscription.trial_end + ONE_DAY:
                if subscription.start_date.month != subscription.trial_end.month:
                    metered_features_billed_up_to = subscription.trial_end

        if subscription.cancel_date:
            if billing_date == subscription.cancel_date:
                plan_billed_up_to = subscription.cancel_date
                metered_features_billed_up_to = subscription.cancel_date

        if subscription.ended_at:
            if billing_date == subscription.ended_at:
                plan_billed_up_to = subscription.ended_at
                metered_features_billed_up_to = subscription.ended_at

        billing_log.plan_billed_up_to = plan_billed_up_to
        billing_log.metered_features_billed_up_to = metered_features_billed_up_to
        billing_log.save(using=db_alias)
def fill_billing_log_billed_up_to_fields(apps, schema_editor):
    # this tries to fill a subscription's billinglogs plan_billed_up_to and
    # metered_features_billed_up_to fields with somewhat sane values

    BillingLog = apps.get_model('silver', 'BillingLog')
    db_alias = schema_editor.connection.alias

    for billing_log in BillingLog.objects.using(db_alias).all():
        subscription = billing_log.subscription
        billing_date = billing_log.billing_date

        plan_billed_up_to = last_day_of_month(billing_date)
        metered_features_billed_up_to = last_day_of_month(prev_month(billing_date))

        if subscription.trial_end:
            if billing_date == subscription.trial_end + ONE_DAY:
                if subscription.start_date.month != subscription.trial_end.month:
                    metered_features_billed_up_to = subscription.trial_end

        if subscription.cancel_date:
            if billing_date == subscription.cancel_date:
                plan_billed_up_to = subscription.cancel_date
                metered_features_billed_up_to = subscription.cancel_date

        if subscription.ended_at:
            if billing_date == subscription.ended_at:
                plan_billed_up_to = subscription.ended_at
                metered_features_billed_up_to = subscription.ended_at

        billing_log.plan_billed_up_to = plan_billed_up_to
        billing_log.metered_features_billed_up_to = metered_features_billed_up_to
        billing_log.save(using=db_alias)
Esempio n. 3
0
class BillingLogFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = BillingLog

    subscription = factory.SubFactory(SubscriptionFactory)

    proforma = factory.SubFactory(
        ProformaFactory,
        customer=factory.SelfAttribute('..subscription.customer'),
        state=Invoice.STATES.ISSUED,
        issue_date=timezone.now().date(),
    )
    invoice = factory.SubFactory(
        InvoiceFactory,
        customer=factory.SelfAttribute('..subscription.customer'),
        state=Invoice.STATES.ISSUED,
        issue_date=timezone.now().date(),
    )
    billing_date = timezone.now().date()
    plan_billed_up_to = last_day_of_month(timezone.now().date())
    metered_features_billed_up_to = last_day_of_month(prev_month(timezone.now().date()))