From 0cec8b0380b0ea5abf4d3b1b5710786e77c9a764 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Wed, 29 Oct 2025 12:43:12 +0300 Subject: [PATCH] Features: 1) Replace DigitalAssetDownload creation logic with `get_or_create`. Fixes: 1) Remove unnecessary conditional check for DigitalAssetDownload existence. Extra: 1) Simplify flow for processing order products with digital assets. --- core/signals.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/signals.py b/core/signals.py index a8a3945e..44a9d1a5 100644 --- a/core/signals.py +++ b/core/signals.py @@ -125,12 +125,11 @@ def process_order_changes(instance: Order, created: bool, **kwargs: dict[Any, An if has_file: order_product.status = "FINISHED" - if not order_product.download: - DigitalAssetDownload.objects.create(order_product=order_product) - order_product.order.user.payments_balance.amount -= order_product.buy_price # type: ignore [union-attr, operator] - order_product.order.user.payments_balance.save() # type: ignore [union-attr] - order_product.save() - continue + DigitalAssetDownload.objects.get_or_create(order_product=order_product) + order_product.order.user.payments_balance.amount -= order_product.buy_price # type: ignore [union-attr, operator] + order_product.order.user.payments_balance.save() # type: ignore [union-attr] + order_product.save() + continue order_product.save()