Skip to content

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

Remove related objects (#18377)

Marcin Gębalaf6e311006ae0
diff --git a/saleor/core/management/commands/clearorders.py b/saleor/core/management/commands/clearorders.py
index 909c8db5a2..4bcaa08a17 100644
--- a/saleor/core/management/commands/clearorders.py
+++ b/saleor/core/management/commands/clearorders.py
@@ -9,7 +9,12 @@ from django.core.management.base import BaseCommand
from ....account.models import Address, CustomerEvent, CustomerNote, User
from ....checkout.models import Checkout, CheckoutLine, CheckoutMetadata
-from ....discount.models import OrderDiscount, OrderLineDiscount
+from ....discount.models import (
+ CheckoutDiscount,
+ CheckoutLineDiscount,
+ OrderDiscount,
+ OrderLineDiscount,
+)
from ....giftcard.models import GiftCard, GiftCardEvent, GiftCardTag
from ....invoice.models import Invoice, InvoiceEvent
from ....order.models import (
@@ -76,6 +81,12 @@ class Command(BaseCommand):
metadata = CheckoutMetadata.objects.all()
metadata._raw_delete(metadata.db)
+ checkout_discounts = CheckoutDiscount.objects.all()
+ checkout_discounts._raw_delete(checkout_discounts.db)
+
+ checkout_line_discounts = CheckoutLineDiscount.objects.all()
+ checkout_line_discounts._raw_delete(checkout_line_discounts.db)
+
checkout_lines = CheckoutLine.objects.all()
checkout_lines._raw_delete(checkout_lines.db)
@@ -118,6 +129,9 @@ class Command(BaseCommand):
gift_card_tags = GiftCardTag.objects.all()
gift_card_tags.delete()
+ order_gift_cards = Order.gift_cards.through.objects.all()
+ order_gift_cards.delete()
+
gift_cards = GiftCard.objects.all()
gift_cards._raw_delete(gift_cards.db)
self.stdout.write("Removed gift cards")