Repository: fossasia/open-event-server

Issue:
Change the logic of Discount Code to something similar to Eventnook
In eventnook the discount code is applied on individual tickets rather than the total like we do. We need to modify that to follow the way it is done in eventnook and other event organising websites.


Discussion:

Resolving patch:
diff --git a/app/helpers/ticketing.py b/app/helpers/ticketing.py
--- a/app/helpers/ticketing.py
+++ b/app/helpers/ticketing.py
@@ -231,6 +231,7 @@ def create_order(form, from_organizer=False):
             ticket_subtotals = form.getlist('ticket_subtotals[]')
 
         amount = 0
+        total_discount= 0
         for index, id in enumerate(ticket_ids):
             if not string_empty(id) and int(ticket_quantity[index]) > 0:
                 with db.session.no_autoflush:
@@ -243,12 +244,15 @@ def create_order(form, from_organizer=False):
                         amount += float(ticket_subtotals[index])
                     else:
                         amount += (order_ticket.ticket.price * order_ticket.quantity)
+                        if discount and discount.type == "amount":
+                            total_discount += discount.value * order_ticket.quantity
+
         if discount and discount.type == "amount":
-            order.amount = max(amount-discount.value,0)
+            order.amount = max(amount - total_discount,0)
         elif discount:
-            order.amount=amount-(discount.value*amount/100)
+            order.amount = amount - (discount.value * amount / 100.0)
         else:
-            order.amount=amount
+            order.amount = amount
 
         if login.current_user.is_authenticated:
             order.user_id = login.current_user.id
diff --git a/app/views/public/ticketing.py b/app/views/public/ticketing.py
--- a/app/views/public/ticketing.py
+++ b/app/views/public/ticketing.py
@@ -38,9 +38,9 @@ def create_order():
 @ticketing.route('/<order_identifier>/', methods=('GET',))
 def view_order(order_identifier):
     order = TicketingManager.get_and_set_expiry(order_identifier)
-    if not order or order.status == 'expired' or order.status == 'placed':
+    if not order or order.status == 'expired':
         abort(404)
-    if order.status == 'completed':
+    if order.status == 'completed' or order.status == 'placed':
         return redirect(url_for('ticketing.view_order_after_payment', order_identifier=order_identifier))
 
     if order.event.stripe:
diff --git a/app/views/users/ticket_sales.py b/app/views/users/ticket_sales.py
--- a/app/views/users/ticket_sales.py
+++ b/app/views/users/ticket_sales.py
@@ -33,6 +33,12 @@ def display_ticket_stats(event_id):
             'orders_count': 0,
             'total_sales': 0
         },
+        'placed': {
+            'class': 'info',
+            'tickets_count': 0,
+            'orders_count': 0,
+            'total_sales': 0
+        },
         'pending': {
             'class': 'warning',
             'tickets_count': 0,
@@ -57,6 +63,10 @@ def display_ticket_stats(event_id):
                 'tickets_count': 0,
                 'sales': 0
             },
+            'placed': {
+                'tickets_count': 0,
+                'sales': 0
+            },
             'pending': {
                 'tickets_count': 0,
                 'sales': 0


Test patch: