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, base_amount=promotion_amount,
) )
if recipient and promotion_amount and created: if recipient and promotion_amount and created:
with transaction.atomic(): try:
reserved = self.plan.reserve_promotion_amount(promotion_amount) with transaction.atomic():
if reserved: reserved = self.plan.reserve_promotion_amount(promotion_amount)
promotion.promote() if reserved:
else: promotion.promote()
raise Exception('promotion reward not reserved') 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 promotion
return None return None