diff --git a/djstripe/admin.py b/djstripe/admin.py index e99d0a2ba0..716b85e71c 100644 --- a/djstripe/admin.py +++ b/djstripe/admin.py @@ -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 ( @@ -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 @@ -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 diff --git a/djstripe/managers.py b/djstripe/managers.py index da283cf33f..05d806ff02 100644 --- a/djstripe/managers.py +++ b/djstripe/managers.py @@ -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.""" diff --git a/djstripe/migrations/0018_auto_20180110_0559.py b/djstripe/migrations/0018_auto_20180110_0559.py new file mode 100644 index 0000000000..5a4a7e195f --- /dev/null +++ b/djstripe/migrations/0018_auto_20180110_0559.py @@ -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', + ), + ] diff --git a/djstripe/models.py b/djstripe/models.py index 4c8fcd7a9a..74c74399cf 100644 --- a/djstripe/models.py +++ b/djstripe/models.py @@ -15,6 +15,7 @@ import logging import sys import uuid +import warnings from copy import deepcopy from datetime import timedelta @@ -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( @@ -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. diff --git a/tests/test_managers.py b/tests/test_managers.py index 182fdfbadd..199e3941aa 100644 --- a/tests/test_managers.py +++ b/tests/test_managers.py @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/tests/test_stripe_object.py b/tests/test_stripe_object.py index 2df7ed1435..026764181b 100644 --- a/tests/test_stripe_object.py +++ b/tests/test_stripe_object.py @@ -23,7 +23,7 @@ 'description': None, 'livemode': True, 'metadata': None, - 'stripe_timestamp': None + 'created': None }