create promotion outside of atomic

This commit is contained in:
Sayyid Hamid Mahdavi 2025-11-13 10:23:15 +03:30
parent 2a428fbb5d
commit faab09595c

View file

@ -215,12 +215,16 @@ class Recipient(BaseModel):
base_amount=promotion_amount,
)
if recipient and promotion_amount and created:
with transaction.atomic():
reserved = self.plan.reserve_promotion_amount(promotion_amount)
if reserved:
promotion.promote()
else:
raise Exception('promotion reward not reserved')
try:
with transaction.atomic():
reserved = self.plan.reserve_promotion_amount(promotion_amount)
if reserved:
promotion.promote()
else:
raise Exception('promotion reward not reserved')
except Exception as e:
promotion.change_state(from_states=[promotion.state], to_state=PaymentStateChoices.EXPECTED_FAILURE, same_ok=True)
promotion.refresh_from_db()
return promotion
return None