Skip to content

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

Add transaction items deletion to cleardb command (#14198)

Jakubb02c60439c5c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bd93d8aa53..faa3268e52 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ All notable, unreleased changes to this project will be documented in this file.
### Other changes
+- Add transaction items deletion to cleardb command. - #14198 by @jakubkuc
+
# 3.17.0
### Highlights
diff --git a/saleor/core/management/commands/cleardb.py b/saleor/core/management/commands/cleardb.py
index 2e49e61198..d5c4d5a13c 100644
--- a/saleor/core/management/commands/cleardb.py
+++ b/saleor/core/management/commands/cleardb.py
@@ -16,7 +16,7 @@ from ....discount.models import Sale, Voucher
from ....giftcard.models import GiftCard
from ....order.models import Order
from ....page.models import Page, PageType
-from ....payment.models import Payment, Transaction
+from ....payment.models import Payment, Transaction, TransactionItem
from ....product.models import Category, Collection, Product, ProductType
from ....shipping.models import ShippingMethod, ShippingZone
from ....warehouse.models import Warehouse
@@ -46,6 +46,9 @@ class Command(BaseCommand):
Checkout.objects.all().delete()
self.stdout.write("Removed checkouts")
+ TransactionItem.objects.all().delete()
+ self.stdout.write("Removed transaction items")
+
Transaction.objects.all().delete()
self.stdout.write("Removed transactions")
diff --git a/saleor/core/tests/test_core.py b/saleor/core/tests/test_core.py
index 89e94186b1..a5853b8623 100644
--- a/saleor/core/tests/test_core.py
+++ b/saleor/core/tests/test_core.py
@@ -14,6 +14,7 @@ from ...channel.models import Channel
from ...discount.models import Promotion, PromotionRule, Voucher, VoucherChannelListing
from ...giftcard.models import GiftCard, GiftCardEvent
from ...order.models import Order
+from ...payment.models import TransactionItem
from ...product import ProductTypeKind
from ...product.models import ProductType
from ...shipping.models import ShippingZone
@@ -420,6 +421,17 @@ def test_cleardb_preserves_data(admin_user, app, site_settings, staff_user):
staff_user.refresh_from_db()
+@override_settings(DEBUG=True)
+def test_cleardb_remove_orders_and_transactions(transaction_item):
+ transaction_item.refresh_from_db()
+
+ call_command("cleardb")
+ with pytest.raises(TransactionItem.DoesNotExist):
+ transaction_item.refresh_from_db()
+ with pytest.raises(Order.DoesNotExist):
+ transaction_item.order.refresh_from_db()
+
+
def test_prepare_unique_attribute_value_slug(color_attribute):
# given
value_1 = color_attribute.values.first()