Skip to content

Commit

Permalink
Rename stripe_timestamp -> created
Browse files Browse the repository at this point in the history
  • Loading branch information
jleclanche committed Jan 14, 2018
1 parent cd2fed7 commit 349535c
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 19 deletions.
12 changes: 6 additions & 6 deletions djstripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,19 @@ class StripeObjectAdmin(admin.ModelAdmin):
change_form_template = "djstripe/admin/change_form.html"

def get_list_display(self, request):
return ("stripe_id", ) + self.list_display + ("stripe_timestamp", "livemode")
return ("stripe_id", ) + self.list_display + ("created", "livemode")

def get_list_filter(self, request):
return self.list_filter + ("stripe_timestamp", "livemode")
return self.list_filter + ("created", "livemode")

def get_readonly_fields(self, request, obj=None):
return self.readonly_fields + ("stripe_id", "stripe_timestamp")
return self.readonly_fields + ("stripe_id", "created")

def get_search_fields(self, request):
return self.search_fields + ("stripe_id", )

def get_fieldsets(self, request, obj=None):
common_fields = ("livemode", "stripe_id", "stripe_timestamp")
common_fields = ("livemode", "stripe_id", "created")
# Have to remove the fields from the common set, otherwise they'll show up twice.
fields = [f for f in self.get_fields(request, obj) if f not in common_fields]
return (
Expand All @@ -153,7 +153,7 @@ class SubscriptionInline(admin.StackedInline):

model = Subscription
extra = 0
readonly_fields = ("stripe_id", "stripe_timestamp")
readonly_fields = ("stripe_id", "created")
show_change_link = True


Expand Down Expand Up @@ -186,7 +186,7 @@ class InvoiceItemInline(admin.StackedInline):

model = InvoiceItem
extra = 0
readonly_fileds = ("stripe_id", "stripe_timestamp")
readonly_fields = ("stripe_id", "created")
raw_id_fields = ("customer", "subscription")
show_change_link = True

Expand Down
4 changes: 2 additions & 2 deletions djstripe/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class ChargeManager(models.Manager):
"""Manager used by models.Charge."""

def during(self, year, month):
"""Return Charges between a certain time range based on stripe_timestamp."""
return self.filter(stripe_timestamp__year=year, stripe_timestamp__month=month)
"""Return Charges between a certain time range based on `created`."""
return self.filter(created__year=year, created__month=month)

def paid_totals_for(self, year, month):
"""Return paid Charges during a certain year, month with total amount, fee and refunded annotated."""
Expand Down
83 changes: 83 additions & 0 deletions djstripe/migrations/0018_auto_20180110_0559.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Generated by Django 2.0.1 on 2018-01-10 03:59

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('djstripe', '0017_auto_20180110_0553'),
]

operations = [
migrations.RenameField(
model_name='account',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='card',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='charge',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='coupon',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='customer',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='dispute',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='event',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='invoice',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='invoiceitem',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='payout',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='plan',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='source',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='subscription',
old_name='stripe_timestamp',
new_name='created',
),
migrations.RenameField(
model_name='transfer',
old_name='stripe_timestamp',
new_name='created',
),
]
12 changes: 10 additions & 2 deletions djstripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging
import sys
import uuid
import warnings
from copy import deepcopy
from datetime import timedelta

Expand Down Expand Up @@ -131,10 +132,9 @@ class StripeObject(models.Model):
help_text="Null here indicates that the livemode status is unknown or was previously unrecorded. Otherwise, "
"this field indicates whether this record comes from Stripe test mode or live mode operation."
)
stripe_timestamp = StripeDateTimeField(
created = StripeDateTimeField(
null=True,
stripe_required=False,
stripe_name="created",
help_text="The datetime this object was created in stripe."
)
metadata = StripeJSONField(
Expand Down Expand Up @@ -171,6 +171,14 @@ def get_stripe_dashboard_url(self):
def default_api_key(self):
return djstripe_settings.get_default_api_key(self.livemode)

@property
def stripe_timestamp(self):
"""
DEPRECATED(2018-01-10): Use `.created` instead.
"""
warnings.warn("The stripe_timestamp field has been renamed to `created`.", DeprecationWarning)
return self.created

def api_retrieve(self, api_key=None):
"""
Call the stripe API's retrieve operation for this model.
Expand Down
16 changes: 8 additions & 8 deletions tests/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def setUp(self):
self.march_charge = Charge.objects.create(
stripe_id="ch_XXXXMAR1",
customer=customer,
stripe_timestamp=datetime.datetime(2015, 3, 31, tzinfo=timezone.utc),
created=datetime.datetime(2015, 3, 31, tzinfo=timezone.utc),
amount=0,
amount_refunded=0,
currency="usd",
Expand All @@ -182,7 +182,7 @@ def setUp(self):
self.april_charge_1 = Charge.objects.create(
stripe_id="ch_XXXXAPR1",
customer=customer,
stripe_timestamp=datetime.datetime(2015, 4, 1, tzinfo=timezone.utc),
created=datetime.datetime(2015, 4, 1, tzinfo=timezone.utc),
amount=decimal.Decimal("20.15"),
amount_refunded=0,
currency="usd",
Expand All @@ -195,7 +195,7 @@ def setUp(self):
self.april_charge_2 = Charge.objects.create(
stripe_id="ch_XXXXAPR2",
customer=customer,
stripe_timestamp=datetime.datetime(2015, 4, 18, tzinfo=timezone.utc),
created=datetime.datetime(2015, 4, 18, tzinfo=timezone.utc),
amount=decimal.Decimal("10.35"),
amount_refunded=decimal.Decimal("5.35"),
currency="usd",
Expand All @@ -208,7 +208,7 @@ def setUp(self):
self.april_charge_3 = Charge.objects.create(
stripe_id="ch_XXXXAPR3",
customer=customer,
stripe_timestamp=datetime.datetime(2015, 4, 30, tzinfo=timezone.utc),
created=datetime.datetime(2015, 4, 30, tzinfo=timezone.utc),
amount=decimal.Decimal("100.00"),
amount_refunded=decimal.Decimal("80.00"),
currency="usd",
Expand All @@ -221,7 +221,7 @@ def setUp(self):
self.may_charge = Charge.objects.create(
stripe_id="ch_XXXXMAY1",
customer=customer,
stripe_timestamp=datetime.datetime(2015, 5, 1, tzinfo=timezone.utc),
created=datetime.datetime(2015, 5, 1, tzinfo=timezone.utc),
amount=0,
amount_refunded=0,
currency="usd",
Expand All @@ -233,7 +233,7 @@ def setUp(self):
self.november_charge = Charge.objects.create(
stripe_id="ch_XXXXNOV1",
customer=customer,
stripe_timestamp=datetime.datetime(2015, 11, 16, tzinfo=timezone.utc),
created=datetime.datetime(2015, 11, 16, tzinfo=timezone.utc),
amount=0,
amount_refunded=0,
currency="usd",
Expand All @@ -245,7 +245,7 @@ def setUp(self):
self.charge_2014 = Charge.objects.create(
stripe_id="ch_XXXX20141",
customer=customer,
stripe_timestamp=datetime.datetime(2014, 12, 31, tzinfo=timezone.utc),
created=datetime.datetime(2014, 12, 31, tzinfo=timezone.utc),
amount=0,
amount_refunded=0,
currency="usd",
Expand All @@ -257,7 +257,7 @@ def setUp(self):
self.charge_2016 = Charge.objects.create(
stripe_id="ch_XXXX20161",
customer=customer,
stripe_timestamp=datetime.datetime(2016, 1, 1, tzinfo=timezone.utc),
created=datetime.datetime(2016, 1, 1, tzinfo=timezone.utc),
amount=0,
amount_refunded=0,
currency="usd",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stripe_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'description': None,
'livemode': True,
'metadata': None,
'stripe_timestamp': None
'created': None
}


Expand Down

0 comments on commit 349535c

Please sign in to comment.