Skip to content

Commit

Permalink
feat(backend): add discount threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
Adibov committed Nov 30, 2023
1 parent 54dca2d commit a27cce5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/backend_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ class PaymentStatus(models.IntegerChoices):
PAYMENT_CONFIRMED = 1, _('Payment confirmed')
PAYMENT_REJECTED = 2, _('Payment rejected')

_DISCOUNT_THRESHOLD = 200000 # in Tomans
_DISCOUNT_PERCENTAGE = 25 # in percent

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
amount = models.PositiveIntegerField()
user = models.ForeignKey(User, on_delete=models.CASCADE)
Expand Down Expand Up @@ -416,6 +419,8 @@ def create_payment_for_user(user: User):
if len(workshops) == 0 and len(presentations) == 0:
raise ValidationError(
new_detailed_response(status.HTTP_400_BAD_REQUEST, f"User {user} has no unpaid registrations"))
if total_cost >= Payment._DISCOUNT_THRESHOLD:
total_cost = int(total_cost * (1 - Payment._DISCOUNT_PERCENTAGE / 100))
payment = Payment.objects.create(user=user, amount=total_cost, year=datetime.date.today().year,
date=datetime.datetime.now())
payment.workshops.set(workshops)
Expand Down

0 comments on commit a27cce5

Please sign in to comment.