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.
This commit is contained in:
parent
82667216f2
commit
be76a3bb8d
1 changed files with 4 additions and 1 deletions
|
|
@ -80,9 +80,11 @@ def process_order_changes(instance, created, **kwargs):
|
||||||
if instance.status == "CREATED":
|
if instance.status == "CREATED":
|
||||||
if not instance.is_whole_digital:
|
if not instance.is_whole_digital:
|
||||||
send_order_created_email.delay(instance.uuid)
|
send_order_created_email.delay(instance.uuid)
|
||||||
|
|
||||||
for order_product in instance.order_products.filter(status="DELIVERING"):
|
for order_product in instance.order_products.filter(status="DELIVERING"):
|
||||||
if not order_product.product.is_digital:
|
if not order_product.product.is_digital:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vendor_name = (
|
vendor_name = (
|
||||||
order_product.product.stocks.filter(price=order_product.buy_price).first().vendor.name.lower()
|
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:
|
except Exception as e:
|
||||||
order_product.add_error(f"Failed to buy {order_product.uuid}. Reason: {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():
|
if instance.order_products.filter(status="FAILED").count() == instance.order_products.count():
|
||||||
instance.status = "FAILED"
|
instance.status = "FAILED"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue