Skip to content

Commit

Permalink
Remove various usage record fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Aug 29, 2023
1 parent 36f463d commit c9698c2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 58 deletions.
7 changes: 1 addition & 6 deletions djstripe/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,7 @@ def get_actions(self, request):

@admin.register(models.UsageRecordSummary)
class UsageRecordSummaryAdmin(StripeModelAdmin):
list_display = ("invoice", "subscription_item", "total_usage")

def get_queryset(self, request):
return (
super().get_queryset(request).select_related("invoice", "subscription_item")
)
pass


@admin.register(models.WebhookEndpoint)
Expand Down
5 changes: 0 additions & 5 deletions djstripe/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,6 @@ class TaxIdType(Enum):
unknown = _("Unknown")


class UsageAction(Enum):
increment = _("increment")
set = _("set")


class VerificationSessionStatus(Enum):
"""
https://stripe.com/docs/api/identity/verification_sessions/object#identity_verification_session_object-status
Expand Down
46 changes: 3 additions & 43 deletions djstripe/models/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2762,7 +2762,6 @@ class UsageRecord(StripeModel):
related_name="usage_records",
help_text="The subscription item this usage record contains data for.",
)

timestamp = StripeDateTimeField(
null=True,
blank=True,
Expand All @@ -2773,19 +2772,8 @@ class UsageRecord(StripeModel):
),
)

action = StripeEnumField(
enum=enums.UsageAction,
default=enums.UsageAction.increment,
help_text=(
"When using increment the specified quantity will be added to the usage at"
" the specified timestamp. The set action will overwrite the usage quantity"
" at that timestamp. If the subscription has billing thresholds, increment"
" is the only allowed value."
),
)

def __str__(self):
return f"Usage for {self.subscription_item} ({self.action}) is {self.quantity}"
return f"Usage for {self.subscription_item}"

@classmethod
def _api_create(cls, api_key=djstripe_settings.STRIPE_SECRET_KEY, **kwargs):
Expand Down Expand Up @@ -2846,43 +2834,15 @@ class UsageRecordSummary(StripeModel):
on_delete=models.CASCADE,
related_name="usage_record_summaries",
)
period = JSONField(
null=True,
blank=True,
help_text="Subscription Billing period for the SubscriptionItem",
)
period_end = StripeDateTimeField(
null=True,
blank=True,
help_text="End of the Subscription Billing period for the SubscriptionItem",
)
period_start = StripeDateTimeField(
null=True,
blank=True,
help_text="Start of the Subscription Billing period for the SubscriptionItem",
)
total_usage = models.PositiveIntegerField(
help_text="The quantity of the plan to which the customer should be subscribed."
)
subscription_item = StripeForeignKey(
"SubscriptionItem",
SubscriptionItem,
on_delete=models.CASCADE,
related_name="usage_record_summaries",
help_text="The subscription item this usage record contains data for.",
)

def __str__(self):
return (
f"Usage Summary for {self.subscription_item} ({self.invoice}) is"
f" {self.total_usage}"
)

@classmethod
def _manipulate_stripe_object_hook(cls, data):
data["period_start"] = data["period"]["start"]
data["period_end"] = data["period"]["end"]

return data
return f"Usage Summary for {self.subscription_item} ({self.invoice})"

@classmethod
def api_list(cls, api_key=djstripe_settings.STRIPE_SECRET_KEY, **kwargs):
Expand Down
4 changes: 0 additions & 4 deletions tests/test_usage_record_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ def test___str__(
),
)

@patch(
"stripe.SubscriptionItem.list_usage_record_summaries",
autospec=True,
)
@patch(
"djstripe.models.billing.SubscriptionItem.objects.get",
return_value=deepcopy(FAKE_SUBSCRIPTION_ITEM),
Expand Down

0 comments on commit c9698c2

Please sign in to comment.