From be76a3bb8d58a4de01489b927e0eceffcde166d2 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Sun, 11 May 2025 22:46:45 +0300 Subject: [PATCH] Features: 1) Introduce conditional check ensuring `instance.finalize()` execution only when no order product errors exist; Fixes: 1) Prevent potential incorrect execution of `instance.finalize()` by adding else block; Extra: 1) Add spacing for improved readability; 2) Minor formatting tweaks in signal logic. --- core/signals.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/signals.py b/core/signals.py index e239e363..8d095585 100644 --- a/core/signals.py +++ b/core/signals.py @@ -80,9 +80,11 @@ def process_order_changes(instance, created, **kwargs): if instance.status == "CREATED": if not instance.is_whole_digital: send_order_created_email.delay(instance.uuid) + for order_product in instance.order_products.filter(status="DELIVERING"): if not order_product.product.is_digital: continue + try: vendor_name = ( order_product.product.stocks.filter(price=order_product.buy_price).first().vendor.name.lower() @@ -95,7 +97,8 @@ def process_order_changes(instance, created, **kwargs): except Exception as e: order_product.add_error(f"Failed to buy {order_product.uuid}. Reason: {e}...") - instance.finalize() + else: + instance.finalize() if instance.order_products.filter(status="FAILED").count() == instance.order_products.count(): instance.status = "FAILED"