This commit is contained in:
Sayyid Hamid Mahdavi 2025-11-12 20:04:27 +03:30
parent 6570be7b20
commit 2a428fbb5d

View file

@ -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)