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 f2edef5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions insalan/payment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,19 @@ 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
# Add the discount to the transaction object
transaction_obj.discounts.add(discount)
for discount in discounts:
# Check if the discount is applicable
if amount >= discount.discount:
amount -= discount.discount

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

# helloasso intent
helloasso_amount = int(
Expand Down

0 comments on commit f2edef5

Please sign in to comment.