Skip to content

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

Refresh order to guarantee correct order payment status calculcation (#19323)

Marcin Wcisłofd71e953c95f
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 2d25ebaa46..c90180634a 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -1012,6 +1012,12 @@ def create_fake_order(max_order_lines=5, create_preorder_lines=False):
order.lines_count = order.lines.count()
order.save()
+ # `prepare_order_search_vector_value` above prefetched `payment_transactions`
+ # while the order had none, caching an empty list on the instance. Drop that
+ # stale cache so `create_fake_payment` recalculates charge amounts against the
+ # transaction it creates instead of the cached empty queryset.
+ order.refresh_from_db()
+
create_fake_payment(order=order)
# Ensure totals (including total_balance) reflect the latest transactions