From 2a428fbb5d4cadf6c9e89b30d05eebf2cffccc5c Mon Sep 17 00:00:00 2001 From: Sayyid Hamid Mahdavi Date: Wed, 12 Nov 2025 20:04:27 +0330 Subject: [PATCH] bugfix --- apps/promotions/models.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/apps/promotions/models.py b/apps/promotions/models.py index 905d6be..54ef57d 100644 --- a/apps/promotions/models.py +++ b/apps/promotions/models.py @@ -206,23 +206,19 @@ class Recipient(BaseModel): def promote(self, plan=None, event=None): recipient = self.get_recipient_uuid(plan, event) promotion_amount = self.get_promotion_amount(plan=plan, event=event) - if recipient and promotion_amount: + promotion, created = Promotion.objects.get_or_create( + promotion_amount=promotion_amount, + user_uuid=self.get_recipient_uuid(plan, event), + event=event, + plan=plan, + recipient=self, + base_amount=promotion_amount, + ) + if recipient and promotion_amount and created: with transaction.atomic(): - promotion_amount = self.get_promotion_amount(plan=plan, event=event) reserved = self.plan.reserve_promotion_amount(promotion_amount) if reserved: - promotion, created = Promotion.objects.get_or_create( - promotion_amount=promotion_amount, - user_uuid=self.get_recipient_uuid(plan, event), - event=event, - plan=plan, - recipient=self, - base_amount=promotion_amount, - ) - if created: - promotion.promote() - else: - raise Exception('promotion object not created') + promotion.promote() else: raise Exception('promotion reward not reserved') @@ -246,7 +242,6 @@ class PromotionQuerySet(models.QuerySet): class Promotion(BaseModel): - user_uuid = models.UUIDField() # user_uuid application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL, on_delete=models.PROTECT, related_name='+', null=True, blank=True)