Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Rename created fields to created_at in models (#9537)

Iga Karbowiak178a27e57659
diff --git a/saleor/app/migrations/0012_rename_created_app_created_at.py b/saleor/app/migrations/0012_rename_created_app_created_at.py
new file mode 100644
index 0000000000..4766b7f62a
--- /dev/null
+++ b/saleor/app/migrations/0012_rename_created_app_created_at.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.12 on 2022-04-14 10:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("app", "0011_alter_apptoken_token_last_4"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="app",
+ old_name="created",
+ new_name="created_at",
+ ),
+ ]
diff --git a/saleor/app/models.py b/saleor/app/models.py
index 671ecbeb4b..7619402543 100644
--- a/saleor/app/models.py
+++ b/saleor/app/models.py
@@ -31,7 +31,7 @@ class AppQueryset(models.QuerySet):
class App(ModelWithMetadata):
name = models.CharField(max_length=60)
- created = models.DateTimeField(auto_now_add=True)
+ created_at = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
type = models.CharField(
choices=AppType.CHOICES, default=AppType.LOCAL, max_length=60
diff --git a/saleor/checkout/migrations/0042_rename_created_checkout_created_at.py b/saleor/checkout/migrations/0042_rename_created_checkout_created_at.py
new file mode 100644
index 0000000000..3bd4ccfd82
--- /dev/null
+++ b/saleor/checkout/migrations/0042_rename_created_checkout_created_at.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.12 on 2022-04-14 10:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("checkout", "0041_checkoutline_price_override"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="checkout",
+ old_name="created",
+ new_name="created_at",
+ ),
+ ]
diff --git a/saleor/checkout/models.py b/saleor/checkout/models.py
index 11257347ff..74aa3b9da2 100644
--- a/saleor/checkout/models.py
+++ b/saleor/checkout/models.py
@@ -37,7 +37,7 @@ def get_default_country():
class Checkout(ModelWithMetadata):
"""A shopping checkout."""
- created = models.DateTimeField(auto_now_add=True)
+ created_at = models.DateTimeField(auto_now_add=True)
last_change = models.DateTimeField(auto_now=True)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
diff --git a/saleor/checkout/tests/test_checkout_complete.py b/saleor/checkout/tests/test_checkout_complete.py
index fb4c0e74d7..f0c1a15e23 100644
--- a/saleor/checkout/tests/test_checkout_complete.py
+++ b/saleor/checkout/tests/test_checkout_complete.py
@@ -131,8 +131,8 @@ def test_create_order_captured_payment_creates_expected_events(
"order": get_default_order_payload(order),
"recipient_email": order.get_customer_email(),
"payment": {
- "created": payment_txn_captured.created,
- "modified": payment_txn_captured.modified,
+ "created": payment_txn_captured.created_at,
+ "modified": payment_txn_captured.modified_at,
"charge_status": payment_txn_captured.charge_status,
"total": payment_txn_captured.total,
"captured_amount": payment_txn_captured.captured_amount,
@@ -281,8 +281,8 @@ def test_create_order_captured_payment_creates_expected_events_anonymous_user(
"order": get_default_order_payload(order),
"recipient_email": order.get_customer_email(),
"payment": {
- "created": payment_txn_captured.created,
- "modified": payment_txn_captured.modified,
+ "created": payment_txn_captured.created_at,
+ "modified": payment_txn_captured.modified_at,
"charge_status": payment_txn_captured.charge_status,
"total": payment_txn_captured.total,
"captured_amount": payment_txn_captured.captured_amount,
diff --git a/saleor/checkout/tests/test_tasks.py b/saleor/checkout/tests/test_tasks.py
index 8033a8f30e..a6d96972b1 100644
--- a/saleor/checkout/tests/test_tasks.py
+++ b/saleor/checkout/tests/test_tasks.py
@@ -15,7 +15,7 @@ def test_delete_expired_anonymous_checkouts(checkouts_list, variant, customer_us
expired_anonymous_checkout = checkouts_list[0]
expired_anonymous_checkout.email = None
expired_anonymous_checkout.user = None
- expired_anonymous_checkout.created = now - timedelta(days=40)
+ expired_anonymous_checkout.created_at = now - timedelta(days=40)
expired_anonymous_checkout.last_change = now - timedelta(days=35)
expired_anonymous_checkout.lines.create(
checkout=expired_anonymous_checkout, variant=variant, quantity=1
@@ -24,7 +24,7 @@ def test_delete_expired_anonymous_checkouts(checkouts_list, variant, customer_us
not_expired_checkout_1 = checkouts_list[1]
not_expired_checkout_1.email = None
not_expired_checkout_1.user = None
- not_expired_checkout_1.created = now - timedelta(days=35)
+ not_expired_checkout_1.created_at = now - timedelta(days=35)
not_expired_checkout_1.last_change = now - timedelta(days=29)
not_expired_checkout_1.lines.create(
checkout=not_expired_checkout_1, variant=variant, quantity=1
@@ -33,7 +33,7 @@ def test_delete_expired_anonymous_checkouts(checkouts_list, variant, customer_us
not_expired_checkout_2 = checkouts_list[2]
not_expired_checkout_2.email = None
not_expired_checkout_2.user = customer_user
- not_expired_checkout_2.created = now - timedelta(days=45)
+ not_expired_checkout_2.created_at = now - timedelta(days=45)
not_expired_checkout_2.last_change = now - timedelta(days=40)
not_expired_checkout_2.lines.create(
checkout=not_expired_checkout_2, variant=variant, quantity=1
@@ -42,7 +42,7 @@ def test_delete_expired_anonymous_checkouts(checkouts_list, variant, customer_us
not_expired_checkout_3 = checkouts_list[3]
not_expired_checkout_3.email = "[email protected]"
not_expired_checkout_3.user = None
- not_expired_checkout_3.created = now - timedelta(days=45)
+ not_expired_checkout_3.created_at = now - timedelta(days=45)
not_expired_checkout_3.last_change = now - timedelta(days=40)
not_expired_checkout_3.lines.create(
checkout=not_expired_checkout_3, variant=variant, quantity=1
@@ -59,7 +59,7 @@ def test_delete_expired_anonymous_checkouts(checkouts_list, variant, customer_us
not_expired_checkout_2,
not_expired_checkout_3,
],
- ["created", "last_change", "email", "user"],
+ ["created_at", "last_change", "email", "user"],
)
# when
@@ -79,7 +79,7 @@ def test_delete_expired_user_checkouts(checkouts_list, variant, customer_user):
expired_user_checkout_1 = checkouts_list[0]
expired_user_checkout_1.email = None
expired_user_checkout_1.user = customer_user
- expired_user_checkout_1.created = now - timedelta(days=100)
+ expired_user_checkout_1.created_at = now - timedelta(days=100)
expired_user_checkout_1.last_change = now - timedelta(days=98)
expired_user_checkout_1.lines.create(
checkout=expired_user_checkout_1, variant=variant, quantity=1
@@ -88,7 +88,7 @@ def test_delete_expired_user_checkouts(checkouts_list, variant, customer_user):
expired_user_checkout_2 = checkouts_list[1]
expired_user_checkout_2.email = "[email protected]"
expired_user_checkout_2.user = None
- expired_user_checkout_2.created = now - timedelta(days=100)
+ expired_user_checkout_2.created_at = now - timedelta(days=100)
expired_user_checkout_2.last_change = now - timedelta(days=91)
expired_user_checkout_2.lines.create(
checkout=expired_user_checkout_2, variant=variant, quantity=1
@@ -97,7 +97,7 @@ def test_delete_expired_user_checkouts(checkouts_list, variant, customer_user):
not_expired_checkout_1 = checkouts_list[2]
not_expired_checkout_1.email = None
not_expired_checkout_1.user = None
- not_expired_checkout_1.created = now - timedelta(days=35)
+ not_expired_checkout_1.created_at = now - timedelta(days=35)
not_expired_checkout_1.last_change = now - timedelta(days=29)
not_expired_checkout_1.lines.create(
checkout=not_expired_checkout_1, variant=variant, quantity=1
@@ -106,7 +106,7 @@ def test_delete_expired_user_checkouts(checkouts_list, variant, customer_user):
not_expired_checkout_2 = checkouts_list[3]
not_expired_checkout_2.email = "[email protected]"
not_expired_checkout_2.user = None
- not_expired_checkout_2.created = now - timedelta(days=100)
+ not_expired_checkout_2.created_at = now - timedelta(days=100)
not_expired_checkout_2.last_change = now - timedelta(days=60)
not_expired_checkout_2.lines.create(
checkout=not_expired_checkout_2, variant=variant, quantity=1
@@ -115,7 +115,7 @@ def test_delete_expired_user_checkouts(checkouts_list, variant, customer_user):
not_expired_checkout_3 = checkouts_list[4]
not_expired_checkout_3.email = None
not_expired_checkout_3.user = customer_user
- not_expired_checkout_3.created = now - timedelta(days=100)
+ not_expired_checkout_3.created_at = now - timedelta(days=100)
not_expired_checkout_3.last_change = now - timedelta(days=89)
not_expired_checkout_3.lines.create(
checkout=not_expired_checkout_3, variant=variant, quantity=1
@@ -129,7 +129,7 @@ def test_delete_expired_user_checkouts(checkouts_list, variant, customer_user):
not_expired_checkout_2,
not_expired_checkout_3,
],
- ["created", "last_change", "email", "user"],
+ ["created_at", "last_change", "email", "user"],
)
# when
@@ -194,7 +194,7 @@ def test_delete_expired_checkouts(checkouts_list, customer_user, variant):
expired_anonymous_checkout = checkouts_list[0]
expired_anonymous_checkout.email = None
- expired_anonymous_checkout.created = now - timedelta(days=40)
+ expired_anonymous_checkout.created_at = now - timedelta(days=40)
expired_anonymous_checkout.last_change = now - timedelta(days=35)
expired_anonymous_checkout.lines.create(
checkout=expired_anonymous_checkout, variant=variant, quantity=1
@@ -202,7 +202,7 @@ def test_delete_expired_checkouts(checkouts_list, customer_user, variant):
expired_user_checkout = checkouts_list[2]
expired_user_checkout.user = customer_user
- expired_user_checkout.created = now - timedelta(days=100)
+ expired_user_checkout.created_at = now - timedelta(days=100)
expired_user_checkout.last_change = now - timedelta(days=95)
expired_user_checkout.lines.create(
checkout=expired_user_checkout, variant=variant, quantity=1
@@ -218,7 +218,7 @@ def test_delete_expired_checkouts(checkouts_list, customer_user, variant):
expired_user_checkout,
empty_checkout,
],
- ["created", "last_change", "email", "user"],
+ ["created_at", "last_change", "email", "user"],
)
# when
diff --git a/saleor/discount/migrations/0039_rename_created_sale_created_at.py b/saleor/discount/migrations/0039_rename_created_sale_created_at.py
new file mode 100644
index 0000000000..886312c75f
--- /dev/null
+++ b/saleor/discount/migrations/0039_rename_created_sale_created_at.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.12 on 2022-04-14 10:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("discount", "0038_alter_orderdiscount_options"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="sale",
+ old_name="created",
+ new_name="created_at",
+ ),
+ ]
diff --git a/saleor/discount/models.py b/saleor/discount/models.py
index 5aa2ecc7e2..9007c98099 100644
--- a/saleor/discount/models.py
+++ b/saleor/discount/models.py
@@ -264,7 +264,7 @@ class Sale(ModelWithMetadata):
variants = models.ManyToManyField("product.ProductVariant", blank=True)
start_date = models.DateTimeField(default=timezone.now)
end_date = models.DateTimeField(null=True, blank=True)
- created = models.DateTimeField(auto_now_add=True, db_index=True)
+ created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True, db_index=True)
objects = models.Manager.from_queryset(SaleQueryset)()
diff --git a/saleor/giftcard/migrations/0015_rename_created_giftcard_created_at.py b/saleor/giftcard/migrations/0015_rename_created_giftcard_created_at.py
new file mode 100644
index 0000000000..b230e4a09c
--- /dev/null
+++ b/saleor/giftcard/migrations/0015_rename_created_giftcard_created_at.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.12 on 2022-04-14 10:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("giftcard", "0014_set_giftcardevent_order_values"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="giftcard",
+ old_name="created",
+ new_name="created_at",
+ ),
+ ]
diff --git a/saleor/giftcard/models.py b/saleor/giftcard/models.py
index 4bb0a2ef30..e147f0ce42 100644
--- a/saleor/giftcard/models.py
+++ b/saleor/giftcard/models.py
@@ -67,7 +67,7 @@ class GiftCard(ModelWithMetadata):
expiry_date = models.DateField(null=True, blank=True)
tags = models.ManyToManyField(GiftCardTag, "gift_cards")
- created = models.DateTimeField(auto_now_add=True)
+ created_at = models.DateTimeField(auto_now_add=True)
last_used_on = models.DateTimeField(null=True, blank=True)
product = models.ForeignKey(
"product.Product",
diff --git a/saleor/graphql/account/filters.py b/saleor/graphql/account/filters.py
index 84719d4162..3632808feb 100644
--- a/saleor/graphql/account/filters.py
+++ b/saleor/graphql/account/filters.py
@@ -29,7 +29,7 @@ def filter_number_of_orders(qs, _, value):
def filter_placed_orders(qs, _, value):
- return filter_range_field(qs, "orders__created__date", value)
+ return filter_range_field(qs, "orders__created_at__date", value)
def filter_staff_status(qs, _, value):
diff --git a/saleor/graphql/app/sorters.py b/saleor/graphql/app/sorters.py
index 8c7ee40e3c..6062a2d039 100644
--- a/saleor/graphql/app/sorters.py
+++ b/saleor/graphql/app/sorters.py
@@ -5,7 +5,7 @@ from ..core.types import SortInputObjectType
class AppSortField(graphene.Enum):
NAME = ["name", "pk"]
- CREATION_DATE = ["created", "name", "pk"]
+ CREATION_DATE = ["created_at", "name", "pk"]
@property
def description(self):
diff --git a/saleor/graphql/app/types.py b/saleor/graphql/app/types.py
index 81ed074eb8..5b37a1ddae 100644
--- a/saleor/graphql/app/types.py
+++ b/saleor/graphql/app/types.py
@@ -217,6 +217,10 @@ class App(ModelObjectType):
interfaces = [graphene.relay.Node, ObjectWithMetadata]
model = models.App
+ @staticmethod
+ def resolve_created(root: models.App, _info):
+ return root.created_at
+
@staticmethod
def resolve_permissions(root: models.App, _info, **_kwargs):
permissions = root.permissions.prefetch_related("content_type").order_by(
diff --git a/saleor/graphql/checkout/filters.py b/saleor/graphql/checkout/filters.py
index 4073f3e368..c0d4e51208 100644
--- a/saleor/graphql/checkout/filters.py
+++ b/saleor/graphql/checkout/filters.py
@@ -42,7 +42,7 @@ def filter_checkout_by_payment(qs, payment_id):
def filter_created_range(qs, _, value):
- return filter_range_field(qs, "created__date", value)
+ return filter_range_field(qs, "created_at__date", value)
def filter_customer(qs, _, value):
diff --git a/saleor/graphql/checkout/sorters.py b/saleor/graphql/checkout/sorters.py
index a35ec42e72..0af42432e5 100644
--- a/saleor/graphql/checkout/sorters.py
+++ b/saleor/graphql/checkout/sorters.py
@@ -6,7 +6,7 @@ from ..core.types import SortInputObjectType
class CheckoutSortField(graphene.Enum):
- CREATION_DATE = ["created", "pk"]
+ CREATION_DATE = ["created_at", "pk"]
CUSTOMER = ["billing_address__last_name", "billing_address__first_name", "pk"]
PAYMENT = ["last_charge_status", "pk"]
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index 169ce35a73..63e1d10764 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -280,6 +280,10 @@ class Checkout(ModelObjectType):
model = models.Checkout
interfaces = [graphene.relay.Node, ObjectWithMetadata]
+ @staticmethod
+ def resolve_created(root: models.Checkout, _info):
+ return root.created_at
+
@staticmethod
def resolve_id(root: models.Checkout, _):
return graphene.Node.to_global_id("Checkout", root.pk)
diff --git a/saleor/graphql/discount/sorters.py b/saleor/graphql/discount/sorters.py
index 90a272bf89..6fb7a02db1 100644
--- a/saleor/graphql/discount/sorters.py
+++ b/saleor/graphql/discount/sorters.py
@@ -10,7 +10,7 @@ class SaleSortField(graphene.Enum):
END_DATE = ["end_date", "name", "pk"]
VALUE = ["value", "name", "pk"]
TYPE = ["type", "name", "pk"]
- CREATED_AT = ["created", "name", "pk"]
+ CREATED_AT = ["created_at", "name", "pk"]
LAST_MODIFIED_AT = ["updated_at", "name", "pk"]
@property
diff --git a/saleor/graphql/discount/types.py b/saleor/graphql/discount/types.py
index 79fe919eeb..c07ee122be 100644
--- a/saleor/graphql/discount/types.py
+++ b/saleor/graphql/discount/types.py
@@ -101,6 +101,10 @@ class Sale(ChannelContextTypeWithMetadata, ModelObjectType):
interfaces = [relay.Node, ObjectWithMetadata]
model = models.Sale
+ @staticmethod
+ def resolve_created(root: models.Sale, _info):
+ return root.created_at
+
@staticmethod
def resolve_categories(root: ChannelContext[models.Sale], info, *_args, **kwargs):
qs = root.node.categories.all()
diff --git a/saleor/graphql/giftcard/sorters.py b/saleor/graphql/giftcard/sorters.py
index 68e5b831d3..4f42882f02 100644
--- a/saleor/graphql/giftcard/sorters.py
+++ b/saleor/graphql/giftcard/sorters.py
@@ -5,8 +5,8 @@ from ..core.types import SortInputObjectType
class GiftCardSortField(graphene.Enum):
PRODUCT = ["product__name", "product__slug"]
- USED_BY = ["used_by__first_name", "used_by__last_name", "created"]
- CURRENT_BALANCE = ["current_balance_amount", "created"]
+ USED_BY = ["used_by__first_name", "used_by__last_name", "created_at"]
+ CURRENT_BALANCE = ["current_balance_amount", "created_at"]
@property
def description(self):
diff --git a/saleor/graphql/giftcard/tests/queries/test_gift_card.py b/saleor/graphql/giftcard/tests/queries/test_gift_card.py
index c9579557ad..55f30fac39 100644
--- a/saleor/graphql/giftcard/tests/queries/test_gift_card.py
+++ b/saleor/graphql/giftcard/tests/queries/test_gift_card.py
@@ -87,7 +87,7 @@ def test_query_gift_card_with_permissions(
assert data["isActive"] == gift_card.is_active
assert data["expiryDate"] is None
assert data["tags"][0]["name"] == gift_card.tags.first().name
- assert data["created"] == gift_card.created.isoformat()
+ assert data["created"] == gift_card.created_at.isoformat()
assert data["lastUsedOn"] == gift_card.last_used_on
assert data["boughtInChannel"] is None
assert data["initialBalance"]["currency"] == gift_card.initial_balance.currency
@@ -152,7 +152,7 @@ def test_query_gift_card_by_app(
assert data["isActive"] == gift_card.is_active
assert data["expiryDate"] is None
assert data["tags"][0]["name"] == gift_card.tags.first().name
- assert data["created"] == gift_card.created.isoformat()
+ assert data["created"] == gift_card.created_at.isoformat()
assert data["lastUsedOn"] == gift_card.last_used_on
assert data["initialBalance"]["currency"] == gift_card.initial_balance.currency
assert data["initialBalance"]["amount"] == gift_card.initial_balance.amount
diff --git a/saleor/graphql/giftcard/tests/queries/test_gift_card_sorting.py b/saleor/graphql/giftcard/tests/queries/test_gift_card_sorting.py
index 9c44102a95..382f16c133 100644
--- a/saleor/graphql/giftcard/tests/queries/test_gift_card_sorting.py
+++ b/saleor/graphql/giftcard/tests/queries/test_gift_card_sorting.py
@@ -150,10 +150,10 @@ def test_sorting_gift_cards_by_used_by(
permission_manage_gift_card,
):
# given
- gift_card.created = timezone.now() - datetime.timedelta(days=10)
- gift_card_expiry_date.created = timezone.now()
+ gift_card.created_at = timezone.now() - datetime.timedelta(days=10)
+ gift_card_expiry_date.created_at = timezone.now()
gift_card_list = [gift_card_used, gift_card, gift_card_expiry_date]
- GiftCard.objects.bulk_update(gift_card_list, ["created"])
+ GiftCard.objects.bulk_update(gift_card_list, ["created_at"])
variables = {
"sortBy": {
diff --git a/saleor/graphql/giftcard/types.py b/saleor/graphql/giftcard/types.py
index 1e1476f1ae..066b431d94 100644
--- a/saleor/graphql/giftcard/types.py
+++ b/saleor/graphql/giftcard/types.py
@@ -324,6 +324,10 @@ class GiftCard(ModelObjectType):
interfaces = [graphene.relay.Node, ObjectWithMetadata]
model = models.GiftCard
+ @staticmethod
+ def resolve_created(root: models.GiftCard, _info):
+ return root.created_at
+
@staticmethod
def resolve_last_4_code_chars(root: models.GiftCard, *_args, **_kwargs):
return root.display_code
diff --git a/saleor/graphql/order/filters.py b/saleor/graphql/order/filters.py
index 9334d3a2f8..d4a3881d87 100644
--- a/saleor/graphql/order/filters.py
+++ b/saleor/graphql/order/filters.py
@@ -68,7 +68,7 @@ def filter_customer(qs, _, value):
def filter_created_range(qs, _, value):
- return filter_range_field(qs, "created__date", value)
+ return filter_range_field(qs, "created_at__date", value)
def filter_updated_at_range(qs, _, value):
diff --git a/saleor/graphql/order/resolvers.py b/saleor/graphql/order/resolvers.py
index 1110de1747..671677c1e3 100644
--- a/saleor/graphql/order/resolvers.py
+++ b/saleor/graphql/order/resolvers.py
@@ -38,7 +38,7 @@ def resolve_orders_total(_info, period, channel_slug):
.exclude(status=OrderStatus.CANCELED)
.filter(channel__slug=str(channel_slug))
)
- qs = filter_by_period(qs, period, "created")
+ qs = filter_by_period(qs, period, "created_at")
return sum_order_totals(qs, channel.currency_code)
diff --git a/saleor/graphql/order/sorters.py b/saleor/graphql/order/sorters.py
index e0166f232f..2aa0cd16f0 100644
--- a/saleor/graphql/order/sorters.py
+++ b/saleor/graphql/order/sorters.py
@@ -8,8 +8,8 @@ from ..core.types import SortInputObjectType
class OrderSortField(graphene.Enum):
NUMBER = ["number"]
- CREATION_DATE = ["created", "status", "pk"]
- CREATED_AT = ["created", "status", "pk"]
+ CREATION_DATE = ["created_at", "status", "pk"]
+ CREATED_AT = ["created_at", "status", "pk"]
LAST_MODIFIED_AT = ["updated_at", "status", "pk"]
CUSTOMER = ["billing_address__last_name", "billing_address__first_name", "pk"]
PAYMENT = ["last_charge_status", "status", "pk"]
diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.py
index 9d9c2ceecf..a952136ea1 100644
--- a/saleor/graphql/order/tests/test_order.py
+++ b/saleor/graphql/order/tests/test_order.py
@@ -5392,8 +5392,8 @@ def test_order_capture(
"order": get_default_order_payload(order),
"recipient_email": order.get_customer_email(),
"payment": {
- "created": payment.created,
- "modified": payment.modified,
+ "created": payment.created_at,
+ "modified": payment.modified_at,
"charge_status": payment.charge_status,
"total": payment.total,
"captured_amount": payment.captured_amount,
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 10d7c7f3d5..dd1eef6932 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -420,6 +420,10 @@ class Fulfillment(ModelObjectType):
interfaces = [relay.Node, ObjectWithMetadata]
model = models.Fulfillment
+ @staticmethod
+ def resolve_created(root: models.Fulfillment, _info):
+ return root.created_at
+
@staticmethod
def resolve_lines(root: models.Fulfillment, _info):
return root.lines.all()
@@ -809,6 +813,10 @@ class Order(ModelObjectType):
interfaces = [relay.Node, ObjectWithMetadata]
model = models.Order
+ @staticmethod
+ def resolve_created(root: models.Order, _info):
+ return root.created_at
+
@staticmethod
def resolve_token(root: models.Order, info):
return root.id
diff --git a/saleor/graphql/page/sorters.py b/saleor/graphql/page/sorters.py
index bd5ad529e9..67895c0d39 100644
--- a/saleor/graphql/page/sorters.py
+++ b/saleor/graphql/page/sorters.py
@@ -7,7 +7,7 @@ class PageSortField(graphene.Enum):
TITLE = ["title", "slug"]
SLUG = ["slug"]
VISIBILITY = ["is_published", "title", "slug"]
- CREATION_DATE = ["created", "title", "slug"]
+ CREATION_DATE = ["created_at", "title", "slug"]
PUBLICATION_DATE = ["publication_date", "title", "slug"]
@property
diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.py
index f0b0b70b83..051963a8f6 100644
--- a/saleor/graphql/page/types.py
+++ b/saleor/graphql/page/types.py
@@ -118,6 +118,10 @@ class Page(ModelObjectType):
interfaces = [graphene.relay.Node, ObjectWithMetadata]
model = models.Page
+ @staticmethod
+ def resolve_created(root: models.Page, _info):
+ return root.created_at
+
@staticmethod
def resolve_page_type(root: models.Page, info):
return PageTypeByIdLoader(info.context).load(root.page_type_id)
diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.py
index eb4499532d..76d180c1dc 100644
--- a/saleor/graphql/payment/types.py
+++ b/saleor/graphql/payment/types.py
@@ -34,6 +34,10 @@ class Transaction(ModelObjectType):
interfaces = [relay.Node]
model = models.Transaction
+ @staticmethod
+ def resolve_created(root: models.Transaction, _info):
+ return root.created_at
+
@staticmethod
def resolve_amount(root: models.Transaction, _info):
return root.get_amount()
@@ -122,6 +126,14 @@ class Payment(ModelObjectType):
interfaces = [relay.Node, ObjectWithMetadata]
model = models.Payment
+ @staticmethod
+ def resolve_created(root: models.Payment, _info):
+ return root.created_at
+
+ @staticmethod
+ def resolve_modified(root: models.Payment, _info):
+ return root.modified_at
+
@staticmethod
@permission_required(OrderPermissions.MANAGE_ORDERS)
def resolve_customer_ip_address(root: models.Payment, _info):
diff --git a/saleor/graphql/product/resolvers.py b/saleor/graphql/product/resolvers.py
index 136c4d3b0b..30bc7d8041 100644
--- a/saleor/graphql/product/resolvers.py
+++ b/saleor/graphql/product/resolvers.py
@@ -157,7 +157,7 @@ def resolve_report_product_sales(period, channel_slug) -> ChannelQsContext:
qs = models.ProductVariant.objects.all()
# filter by period
- qs = filter_by_period(qs, period, "order_lines__order__created")
+ qs = filter_by_period(qs, period, "order_lines__order__created_at")
# annotate quantity
qs = qs.annotate(quantity_ordered=Sum("order_lines__quantity"))
diff --git a/saleor/graphql/product/types/digital_contents.py b/saleor/graphql/product/types/digital_contents.py
index 9550a4c0d4..a501d5f67c 100644
--- a/saleor/graphql/product/types/digital_contents.py
+++ b/saleor/graphql/product/types/digital_contents.py
@@ -22,6 +22,10 @@ class DigitalContentUrl(ModelObjectType):
model = models.DigitalContentUrl
interfaces = (relay.Node,)
+ @staticmethod
+ def resolve_created(root: models.DigitalContentUrl, _info):
+ return root.created_at
+
@staticmethod
def resolve_url(root: models.DigitalContentUrl, *_args):
return root.get_absolute_url()
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index aeb7c82f2d..d5e6fe6c10 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -332,6 +332,10 @@ class ProductVariant(ChannelContextTypeWithMetadata, ModelObjectType):
interfaces = [relay.Node, ObjectWithMetadata]
model = models.ProductVariant
+ @staticmethod
+ def resolve_created(root: models.ProductVariant, _info):
+ return root.created_at
+
@staticmethod
def resolve_channel(root: ChannelContext[models.Product], info):
return root.channel_slug
@@ -826,6 +830,10 @@ class Product(ChannelContextTypeWithMetadata, ModelObjectType):
interfaces = [relay.Node, ObjectWithMetadata]
model = models.Product
+ @staticmethod
+ def resolve_created(root: models.Product, _info):
+ return root.created_at
+
@staticmethod
def resolve_channel(root: ChannelContext[models.Product], info):
return root.channel_slug
diff --git a/saleor/order/actions.py b/saleor/order/actions.py
index 7ba0384e74..ab28fb9ba2 100644
--- a/saleor/order/actions.py
+++ b/saleor/order/actions.py
@@ -497,7 +497,7 @@ def mark_order_as_paid(
)
payment.charge_status = ChargeStatus.FULLY_CHARGED
payment.captured_amount = order.total.gross.amount
- payment.save(update_fields=["captured_amount", "charge_status", "modified"])
+ payment.save(update_fields=["captured_amount", "charge_status", "modified_at"])
Transaction.objects.create(
payment=payment,
diff --git a/saleor/order/migrations/0136_auto_20220414_1025.py b/saleor/order/migrations/0136_auto_20220414_1025.py
new file mode 100644
index 0000000000..edee552a5a
--- /dev/null
+++ b/saleor/order/migrations/0136_auto_20220414_1025.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.2.12 on 2022-04-14 10:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("order", "0135_alter_order_options"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="fulfillment",
+ old_name="created",
+ new_name="created_at",
+ ),
+ migrations.RenameField(
+ model_name="order",
+ old_name="created",
+ new_name="created_at",
+ ),
+ ]
diff --git a/saleor/order/models.py b/saleor/order/models.py
index fee2d0f433..c86493ad68 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -94,7 +94,7 @@ class Order(ModelWithMetadata):
number = models.IntegerField(unique=True, default=get_order_number, editable=False)
use_old_id = models.BooleanField(default=False)
- created = models.DateTimeField(default=now, editable=False)
+ created_at = models.DateTimeField(default=now, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False, db_index=True)
status = models.CharField(
max_length=32, default=OrderStatus.UNFULFILLED, choices=OrderStatus.CHOICES
@@ -608,7 +608,7 @@ class Fulfillment(ModelWithMetadata):
choices=FulfillmentStatus.CHOICES,
)
tracking_number = models.CharField(max_length=255, default="", blank=True)
- created = models.DateTimeField(auto_now_add=True)
+ created_at = models.DateTimeField(auto_now_add=True)
shipping_refund_amount = models.DecimalField(
max_digits=settings.DEFAULT_MAX_DIGITS,
diff --git a/saleor/order/notifications.py b/saleor/order/notifications.py
index a047f98e50..7ebe9d5637 100644
--- a/saleor/order/notifications.py
+++ b/saleor/order/notifications.py
@@ -246,7 +246,7 @@ def get_default_order_payload(order: "Order", redirect_url: str = ""):
"token": order.id, # DEPRECATED: will be removed in Saleor 4.0.
"number": order.id,
"channel_slug": order.channel.slug,
- "created": str(order.created),
+ "created": str(order.created_at),
"shipping_price_net_amount": order.shipping_price_net_amount,
"shipping_price_gross_amount": order.shipping_price_gross_amount,
"order_details_url": order_details_url,
@@ -370,8 +370,8 @@ def send_payment_confirmation(order_info, manager):
"order": get_default_order_payload(order_info.order),
"recipient_email": order_info.customer_email,
"payment": {
- "created": payment.created,
- "modified": payment.modified,
+ "created": payment.created_at,
+ "modified": payment.modified_at,
"charge_status": payment.charge_status,
"total": quantize_price(payment.total, payment_currency),
"captured_amount": quantize_price(
diff --git a/saleor/order/tests/test_notifications.py b/saleor/order/tests/test_notifications.py
index bafc191915..55fcfa713a 100644
--- a/saleor/order/tests/test_notifications.py
+++ b/saleor/order/tests/test_notifications.py
@@ -239,7 +239,7 @@ def test_get_default_order_payload(order_line):
"id": to_global_id_or_none(order),
"number": order.id,
"token": order.id,
- "created": str(order.created),
+ "created": str(order.created_at),
"display_gross_prices": order.display_gross_prices,
"currency": order.currency,
"total_gross_amount": order.total_gross_amount,
@@ -312,8 +312,8 @@ def test_send_email_payment_confirmation(mocked_notify, site_settings, payment_d
"order": get_default_order_payload(order),
"recipient_email": order.get_customer_email(),
"payment": {
- "created": payment_dummy.created,
- "modified": payment_dummy.modified,
+ "created": payment_dummy.created_at,
+ "modified": payment_dummy.modified_at,
"charge_status": payment_dummy.charge_status,
"total": payment_dummy.total,
"captured_amount": payment_dummy.captured_amount,
@@ -408,8 +408,8 @@ def test_send_confirmation_emails_without_addresses_for_payment(
"order": get_default_order_payload(order),
"recipient_email": order.get_customer_email(),
"payment": {
- "created": payment_dummy.created,
- "modified": payment_dummy.modified,
+ "created": payment_dummy.created_at,
+ "modified": payment_dummy.modified_at,
"charge_status": payment_dummy.charge_status,
"total": payment_dummy.total,
"captured_amount": payment_dummy.captured_amount,
diff --git a/saleor/page/migrations/0025_rename_created_page_created_at.py b/saleor/page/migrations/0025_rename_created_page_created_at.py
new file mode 100644
index 0000000000..ae0d6b30e3
--- /dev/null
+++ b/saleor/page/migrations/0025_rename_created_page_created_at.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.12 on 2022-04-14 10:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("page", "0024_alter_pagetranslation_language_code"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="page",
+ old_name="created",
+ new_name="created_at",
+ ),
+ ]
diff --git a/saleor/page/models.py b/saleor/page/models.py
index 7b58a55d7f..d1447e8a98 100644
--- a/saleor/page/models.py
+++ b/saleor/page/models.py
@@ -23,7 +23,7 @@ class Page(ModelWithMetadata, SeoModel, PublishableModel):
"PageType", related_name="pages", on_delete=models.CASCADE
)
content = SanitizedJSONField(blank=True, null=True, sanitizer=clean_editor_js)
- created = models.DateTimeField(auto_now_add=True)
+ created_at = models.DateTimeField(auto_now_add=True)
translated = TranslationProxy()
diff --git a/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py b/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py
index 60f637ad7a..363674ea6a 100644
--- a/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py
+++ b/saleor/payment/migrations/0002_transfer_payment_to_payment_method.py
@@ -64,7 +64,7 @@ def create_transactions(method, payment):
return
# Other payments needed to be authorized first
- created = payment.created
+ created = payment.created_at
create_transaction(
method=method,
kind=TransactionKind.AUTH,
@@ -130,7 +130,7 @@ def transfer_payments_to_payment_methods(apps, schema_editor):
payment_method = PaymentMethod.objects.create(
order=pay.order,
gateway=pay.variant,
- created=pay.created,
+ created=pay.created_at,
modified=pay.modified,
billing_first_name=pay.billing_first_name,
billing_last_name=pay.billing_last_name,
diff --git a/saleor/payment/migrations/0034_auto_20220414_1051.py b/saleor/payment/migrations/0034_auto_20220414_1051.py
new file mode 100644
index 0000000000..7e3a211e35
--- /dev/null
+++ b/saleor/payment/migrations/0034_auto_20220414_1051.py
@@ -0,0 +1,28 @@
+# Generated by Django 3.2.12 on 2022-04-14 10:51
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("payment", "0033_rewrite_payment_order_relations"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="payment",
+ old_name="created",
+ new_name="created_at",
+ ),
+ migrations.RenameField(
+ model_name="payment",
+ old_name="modified",
+ new_name="modified_at",
+ ),
+ migrations.RenameField(
+ model_name="transaction",
+ old_name="created",
+ new_name="created_at",
+ ),
+ ]
diff --git a/saleor/payment/models.py b/saleor/payment/models.py
index 50ff84b160..49f290cda4 100644
--- a/saleor/payment/models.py
+++ b/saleor/payment/models.py
@@ -35,8 +35,8 @@ class Payment(ModelWithMetadata):
is_active = models.BooleanField(default=True)
to_confirm = models.BooleanField(default=False)
partial = models.BooleanField(default=False)
- created = models.DateTimeField(auto_now_add=True)
- modified = models.DateTimeField(auto_now=True)
+ created_at = models.DateTimeField(auto_now_add=True)
+ modified_at = models.DateTimeField(auto_now=True)
charge_status = models.CharField(
max_length=20, choices=ChargeStatus.CHOICES, default=ChargeStatus.NOT_CHARGED
)
@@ -119,7 +119,7 @@ class Payment(ModelWithMetadata):
return "Payment(gateway=%s, is_active=%s, created=%s, charge_status=%s)" % (
self.gateway,
self.is_active,
- self.created,
+ self.created_at,
self.charge_status,
)
@@ -218,7 +218,7 @@ class Transaction(models.Model):
and your customers, with a chosen payment method.
"""
- created = models.DateTimeField(auto_now_add=True, editable=False)
+ created_at = models.DateTimeField(auto_now_add=True, editable=False)
payment = models.ForeignKey(
Payment, related_name="transactions", on_delete=models.PROTECT
)
@@ -250,7 +250,7 @@ class Transaction(models.Model):
return "Transaction(type=%s, is_success=%s, created=%s)" % (
self.kind,
self.is_success,
- self.created,
+ self.created_at,
)
def get_amount(self):
diff --git a/saleor/payment/utils.py b/saleor/payment/utils.py
index 2011d1a4a4..c8711d5555 100644
--- a/saleor/payment/utils.py
+++ b/saleor/payment/utils.py
@@ -436,14 +436,14 @@ def update_payment_charge_status(payment, transaction, changed_fields=None):
payment.charge_status = ChargeStatus.PARTIALLY_CHARGED
if payment.get_charge_amount() <= 0:
payment.charge_status = ChargeStatus.FULLY_CHARGED
- changed_fields += ["charge_status", "captured_amount", "modified"]
+ changed_fields += ["charge_status", "captured_amount", "modified_at"]
elif transaction_kind == TransactionKind.VOID:
payment.is_active = False
- changed_fields += ["is_active", "modified"]
+ changed_fields += ["is_active", "modified_at"]
elif transaction_kind == TransactionKind.REFUND:
- changed_fields += ["captured_amount", "modified"]
+ changed_fields += ["captured_amount", "modified_at"]
payment.captured_amount -= transaction.amount
payment.charge_status = ChargeStatus.PARTIALLY_REFUNDED
if payment.captured_amount <= 0:
@@ -467,7 +467,7 @@ def update_payment_charge_status(payment, transaction, changed_fields=None):
payment.charge_status = ChargeStatus.PARTIALLY_CHARGED
if payment.captured_amount <= 0:
payment.charge_status = ChargeStatus.NOT_CHARGED
- changed_fields += ["charge_status", "captured_amount", "modified"]
+ changed_fields += ["charge_status", "captured_amount", "modified_at"]
if changed_fields:
payment.save(update_fields=changed_fields)
transaction.already_processed = True
diff --git a/saleor/plugins/invoicing/plugin.py b/saleor/plugins/invoicing/plugin.py
index bb548dda84..9b9f1f5229 100644
--- a/saleor/plugins/invoicing/plugin.py
+++ b/saleor/plugins/invoicing/plugin.py
@@ -36,6 +36,12 @@ class InvoicingPlugin(BasePlugin):
)
invoice.status = JobStatus.SUCCESS
invoice.save(
- update_fields=["created", "number", "invoice_file", "status", "updated_at"]
+ update_fields=[
+ "created_at",
+ "number",
+ "invoice_file",
+ "status",
+ "updated_at",
+ ]
)
return invoice
diff --git a/saleor/plugins/sendgrid/tests/test_tasks.py b/saleor/plugins/sendgrid/tests/test_tasks.py
index 3b443d96fd..8ba59a166d 100644
--- a/saleor/plugins/sendgrid/tests/test_tasks.py
+++ b/saleor/plugins/sendgrid/tests/test_tasks.py
@@ -527,8 +527,8 @@ def test_send_payment_confirmation_email_task(
"order": get_default_order_payload(order, "http://localhost:8000/redirect"),
"recipient_email": recipient_email,
"payment": {
- "created": payment_dummy.created,
- "modified": payment_dummy.modified,
+ "created": payment_dummy.created_at,
+ "modified": payment_dummy.modified_at,
"charge_status": payment_dummy.charge_status,
"total": payment_dummy.total,
"captured_amount": payment_dummy.captured_amount,
diff --git a/saleor/plugins/user_email/tests/test_notify_events.py b/saleor/plugins/user_email/tests/test_notify_events.py
index d530742dd5..8e33d441f5 100644
--- a/saleor/plugins/user_email/tests/test_notify_events.py
+++ b/saleor/plugins/user_email/tests/test_notify_events.py
@@ -459,8 +459,8 @@ def test_send_payment_confirmation(
"order": get_default_order_payload(order, "http://localhost:8000/redirect"),
"recipient_email": "[email protected]",
"payment": {
- "created": payment_dummy.created,
- "modified": payment_dummy.modified,
+ "created": payment_dummy.created_at,
+ "modified": payment_dummy.modified_at,
"charge_status": payment_dummy.charge_status,
"total": payment_dummy.total,
"captured_amount": payment_dummy.captured_amount,
@@ -488,8 +488,8 @@ def test_send_payment_confirmation_empty_template(
"order": get_default_order_payload(order, "http://localhost:8000/redirect"),
"recipient_email": "[email protected]",
"payment": {
- "created": payment_dummy.created,
- "modified": payment_dummy.modified,
+ "created": payment_dummy.created_at,
+ "modified": payment_dummy.modified_at,
"charge_status": payment_dummy.charge_status,
"total": payment_dummy.total,
"captured_amount": payment_dummy.captured_amount,
diff --git a/saleor/plugins/user_email/tests/test_tasks.py b/saleor/plugins/user_email/tests/test_tasks.py
index bb9152a8a0..08a8a178ff 100644
--- a/saleor/plugins/user_email/tests/test_tasks.py
+++ b/saleor/plugins/user_email/tests/test_tasks.py
@@ -798,8 +798,8 @@ def test_send_payment_confirmation_email_task_default_template(
"order": get_default_order_payload(order, "http://localhost:8000/redirect"),
"recipient_email": recipient_email,
"payment": {
- "created": payment_dummy.created,
- "modified": payment_dummy.modified,
+ "created": payment_dummy.created_at,
+ "modified": payment_dummy.modified_at,
"charge_status": payment_dummy.charge_status,
"total": payment_dummy.total,
"captured_amount": payment_dummy.captured_amount,
@@ -838,8 +838,8 @@ def test_send_payment_confirmation_email_task_custom_template(
"order": get_default_order_payload(order, "http://localhost:8000/redirect"),
"recipient_email": recipient_email,
"payment": {
- "created": payment_dummy.created,
- "modified": payment_dummy.modified,
+ "created": payment_dummy.created_at,
+ "modified": payment_dummy.modified_at,
"charge_status": payment_dummy.charge_status,
"total": payment_dummy.total,
"captured_amount": payment_dummy.captured_amount,
diff --git a/saleor/product/migrations/0163_auto_20220414_1025.py b/saleor/product/migrations/0163_auto_20220414_1025.py
new file mode 100644
index 0000000000..14edc59304
--- /dev/null
+++ b/saleor/product/migrations/0163_auto_20220414_1025.py
@@ -0,0 +1,28 @@
+# Generated by Django 3.2.12 on 2022-04-14 10:25
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("product", "0162_auto_20220228_1233"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="digitalcontenturl",
+ old_name="created",
+ new_name="created_at",
+ ),
+ migrations.RenameField(
+ model_name="product",
+ old_name="created",
+ new_name="created_at",
+ ),
+ migrations.RenameField(
+ model_name="productvariant",
+ old_name="created",
+ new_name="created_at",
+ ),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 337709fe5f..7d12e84ac7 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -404,7 +404,7 @@ class Product(SeoModel, ModelWithMetadata):
null=True,
blank=True,
)
- created = models.DateTimeField(auto_now_add=True, db_index=True)
+ created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True, db_index=True)
charge_taxes = models.BooleanField(default=True)
weight = MeasurementField(
@@ -584,7 +584,7 @@ class ProductVariant(SortableModel, ModelWithMetadata):
quantity_limit_per_customer = models.IntegerField(
blank=True, null=True, validators=[MinValueValidator(1)]
)
- created = models.DateTimeField(auto_now_add=True, db_index=True)
+ created_at = models.DateTimeField(auto_now_add=True, db_index=True)
updated_at = models.DateTimeField(auto_now=True, db_index=True)
weight = MeasurementField(
@@ -766,7 +766,7 @@ class DigitalContentUrl(models.Model):
content = models.ForeignKey(
DigitalContent, related_name="urls", on_delete=models.CASCADE
)
- created = models.DateTimeField(auto_now_add=True)
+ created_at = models.DateTimeField(auto_now_add=True)
download_num = models.IntegerField(default=0)
line = models.OneToOneField(
"order.OrderLine",
diff --git a/saleor/product/utils/__init__.py b/saleor/product/utils/__init__.py
index c92f0806bc..faa64f37b3 100644
--- a/saleor/product/utils/__init__.py
+++ b/saleor/product/utils/__init__.py
@@ -27,7 +27,7 @@ def calculate_revenue_for_variant(
revenue = zero_taxed_money(currency_code)
for order_line in order_lines:
order = orders_dict[order_line.order_id]
- if order.created >= start_date:
+ if order.created_at >= start_date:
revenue += order_line.total_price
return revenue
diff --git a/saleor/product/utils/digital_products.py b/saleor/product/utils/digital_products.py
index 6da1206c41..d6f604a37a 100644
--- a/saleor/product/utils/digital_products.py
+++ b/saleor/product/utils/digital_products.py
@@ -33,7 +33,7 @@ def digital_content_url_is_valid(content_url: DigitalContentUrl) -> bool:
if url_valid_days is not None:
valid_days = timedelta(days=url_valid_days)
- valid_until = content_url.created + valid_days
+ valid_until = content_url.created_at + valid_days
if now() > valid_until:
return False
diff --git a/saleor/seo/schema/email.py b/saleor/seo/schema/email.py
index 85739548e2..af6627790a 100644
--- a/saleor/seo/schema/email.py
+++ b/saleor/seo/schema/email.py
@@ -60,7 +60,7 @@ def get_order_confirmation_markup(order: "Order") -> str:
"price": order.total.gross.amount,
"acceptedOffer": [],
"orderStatus": "http://schema.org/OrderProcessing",
- "orderDate": order.created,
+ "orderDate": order.created_at,
}
for line in order.lines.all():
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
index 7b71ebdb75..a88e95e3c0 100644
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -3992,7 +3992,7 @@ def fulfilled_order(order_with_lines):
order.invoices.create(
url="http://www.example.com/invoice.pdf",
number="01/12/2020/TEST",
- created=datetime.datetime.now(tz=pytz.utc),
+ created_at=datetime.datetime.now(tz=pytz.utc),
status=JobStatus.SUCCESS,
)
fulfillment = order.fulfillments.create(tracking_number="123")
diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.py
index 80c5ab13a3..192df374f4 100644
--- a/saleor/webhook/payloads.py
+++ b/saleor/webhook/payloads.py
@@ -51,6 +51,7 @@ if TYPE_CHECKING:
from ..graphql.discount.mutations import NodeCatalogueInfo
from ..invoice.models import Invoice
from ..payment.interface import PaymentData
+ from ..payment.models import Payment
from ..plugins.base_plugin import RequestorOrLazyObject
from ..translation.models import Translation
@@ -70,7 +71,6 @@ ADDRESS_FIELDS = (
)
ORDER_FIELDS = (
- "created",
"status",
"origin",
"shipping_method_name",
@@ -218,36 +218,10 @@ def generate_order_payload(
fulfillment_fields = (
"status",
"tracking_number",
- "created",
"shipping_refund_amount",
"total_refund_amount",
)
fulfillment_price_fields = ("shipping_refund_amount", "total_refund_amount")
- payment_fields = (
- "gateway",
- "payment_method_type",
- "cc_brand",
- "is_active",
- "created",
- "partial",
- "modified",
- "charge_status",
- "psp_reference",
- "total",
- "captured_amount",
- "currency",
- "billing_email",
- "billing_first_name",
- "billing_last_name",
- "billing_company_name",
- "billing_address_1",
- "billing_address_2",
- "billing_city",
- "billing_city_area",
- "billing_postal_code",
- "billing_country_code",
- "billing_country_area",
- )
payment_price_fields = ("captured_amount", "total")
discount_fields = (
"type",
@@ -283,7 +257,8 @@ def generate_order_payload(
fulfillments,
fields=fulfillment_fields,
extra_dict_data={
- "lines": lambda f: json.loads(generate_fulfillment_lines_payload(f))
+ "lines": lambda f: json.loads(generate_fulfillment_lines_payload(f)),
+ "created": lambda f: f.created_at,
},
)
@@ -291,6 +266,7 @@ def generate_order_payload(
"id": graphene.Node.to_global_id("Order", order.id),
"token": str(order.id),
"user_email": order.get_customer_email(),
+ "created": order.created_at,
"original": graphene.Node.to_global_id("Order", order.original_id),
"lines": json.loads(generate_order_lines_payload(lines)),
"fulfillments": json.loads(fulfillments_data),
@@ -299,6 +275,7 @@ def generate_order_payload(
)[0]
if order.collection_point
else None,
+ "payments": json.loads(_generate_order_payment_payload(payments)),
}
if with_meta:
extra_dict_data["meta"] = generate_meta(
@@ -311,7 +288,6 @@ def generate_order_payload(
additional_fields={
"channel": (lambda o: o.channel, channel_fields),
"shipping_method": (lambda o: o.shipping_method, shipping_method_fields),
- "payments": (lambda _: payments, payment_fields),
"shipping_address": (lambda o: o.shipping_address, ADDRESS_FIELDS),
"billing_address": (lambda o: o.billing_address, ADDRESS_FIELDS),
"discounts": (lambda _: discounts, discount_fields),
@@ -321,6 +297,41 @@ def generate_order_payload(
return order_data
+def _generate_order_payment_payload(payments: Iterable["Payment"]):
+ payment_fields = (
+ "gateway",
+ "payment_method_type",
+ "cc_brand",
+ "is_active",
+ "partial",
+ "charge_status",
+ "psp_reference",
+ "total",
+ "captured_amount",
+ "currency",
+ "billing_email",
+ "billing_first_name",
+ "billing_last_name",
+ "billing_company_name",
+ "billing_address_1",
+ "billing_address_2",
+ "billing_city",
+ "billing_city_area",
+ "billing_postal_code",
+ "billing_country_code",
+ "billing_country_area",
+ )
+ serializer = PayloadSerializer()
+ return serializer.serialize(
+ payments,
+ fields=payment_fields,
+ extra_dict_data={
+ "created": lambda p: p.created_at,
+ "modified": lambda p: p.modified_at,
+ },
+ )
+
+
def _calculate_added(
previous_catalogue: "NodeCatalogueInfo",
current_catalogue: "NodeCatalogueInfo",
@@ -419,6 +430,7 @@ def _generate_order_payload_for_invoice(order: "Order"):
extra_dict_data={
"token": order.id,
"user_email": order.get_customer_email(),
+ "created": order.created_at,
},
)
return payload
@@ -430,7 +442,6 @@ def generate_checkout_payload(
):
serializer = PayloadSerializer()
checkout_fields = (
- "created",
"last_change",
"status",
"email",
@@ -483,6 +494,7 @@ def generate_checkout_payload(
if checkout.collection_point
else None,
"meta": generate_meta(requestor_data=generate_requestor(requestor)),
+ "created": checkout.created_at,
},
)
return checkout_data
diff --git a/saleor/webhook/tests/test_webhook_payloads.py b/saleor/webhook/tests/test_webhook_payloads.py
index 4805a87848..09734f441f 100644
--- a/saleor/webhook/tests/test_webhook_payloads.py
+++ b/saleor/webhook/tests/test_webhook_payloads.py
@@ -116,7 +116,7 @@ def test_generate_order_payload(
"id": graphene.Node.to_global_id("Order", order.id),
"type": "Order",
"token": str(order.id),
- "created": parse_django_datetime(order.created),
+ "created": parse_django_datetime(order.created_at),
"status": order.status,
"origin": order.origin,
"user_email": order.user_email,
@@ -148,8 +148,8 @@ def test_generate_order_payload(
"partial": False,
"cc_brand": payment.cc_brand,
"is_active": payment.is_active,
- "created": parse_django_datetime(payment.created),
- "modified": parse_django_datetime(payment.modified),
+ "created": parse_django_datetime(payment.created_at),
+ "modified": parse_django_datetime(payment.modified_at),
"charge_status": payment.charge_status,
"psp_reference": payment.psp_reference,
"total": str(quantize_price(payment.total, currency)),
@@ -230,7 +230,7 @@ def test_generate_order_payload(
"type": "Fulfillment",
"status": fulfillment.status,
"tracking_number": fulfillment.tracking_number,
- "created": parse_django_datetime(fulfillment.created),
+ "created": parse_django_datetime(fulfillment.created_at),
"shipping_refund_amount": "0.00",
"total_refund_amount": "0.00",
"lines": json.loads(fulfillment_lines),
@@ -1114,7 +1114,7 @@ def test_generate_checkout_payload(
assert payload == {
"type": "Checkout",
"token": graphene.Node.to_global_id("Checkout", checkout.pk),
- "created": parse_django_datetime(checkout.created),
+ "created": parse_django_datetime(checkout.created_at),
"last_change": parse_django_datetime(checkout.last_change),
"email": checkout.email,
"currency": checkout.currency,