Skip to content

Commit

Permalink
Fix multi product/discount handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KwikKill committed Dec 27, 2024
1 parent 7783d4b commit 0c9deff
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions insalan/payment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,15 @@ def create(self, request):
{"err": _("Préconditions de paiement non remplies")},
status=status.HTTP_400_BAD_REQUEST,
)

amount = transaction_obj.amount

# If the user has a discount for some products, apply them
for product in transaction_obj.products.all():
discounts = Discount.objects.filter(user=payer, product=product, used=False)
if discounts.exists():
discount = discounts.first()
amount = transaction_obj.amount - discount.discount
for discount in discounts:
amount -= discount.discount

# Add the discount to the transaction object
transaction_obj.discounts.add(discount)

Expand Down

0 comments on commit 0c9deff

Please sign in to comment.