Repository: fossasia/open-event-server

Issue:
Attendees showing only completed orders
Attendees in ticket tab has options for all different tabs but shows on completed orders only.


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
@@ -244,13 +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":
+                        if discount and str(order_ticket.ticket.id) in discount.tickets.split(","):
+                            if discount.type == "amount":
+                                total_discount += discount.value * order_ticket.quantity
+                            else:
+                                total_discount += discount.value * order_ticket.ticket.price *\
+                                                 order_ticket.quantity/100.0
+
+        if discount:
             order.amount = max(amount - total_discount,0)
-        elif discount:
-            order.amount = amount - (discount.value * amount / 100.0)
         else:
             order.amount = amount
 
diff --git a/app/models/discount_code.py b/app/models/discount_code.py
--- a/app/models/discount_code.py
+++ b/app/models/discount_code.py
@@ -59,7 +59,7 @@ def __str__(self):
         return unicode(self).encode('utf-8')
 
     def __unicode__(self):
-        return self.identifier
+        return self.code
     @property
     def serialize(self):
         """Return object data in easily serializable format"""
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
@@ -84,12 +84,20 @@ def display_ticket_stats(event_id):
         orders_summary[str(order.status)]['orders_count'] += 1
         orders_summary[str(order.status)]['total_sales'] += order.amount
         for order_ticket in order.tickets:
+            discount = TicketingManager.get_discount_code(event_id, order.discount_code_id)
             orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity
             ticket = get_ticket(order_ticket.ticket_id)
             tickets_summary[str(ticket.id)][str(order.status)]['tickets_count'] += order_ticket.quantity
             if order.paid_via != 'free' and order.amount > 0:
-                tickets_summary[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * ticket.price
-
+                if discount and str(ticket.id) in discount.tickets.split(","):
+                    if discount.type == "amount":
+                        tickets_summary[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * (ticket.price - \
+                                                                                        discount.value)
+                    else:
+                        tickets_summary[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * (ticket.price - \
+                                                                                        discount.value * ticket.price / 100.0)
+                else:
+                    tickets_summary[str(ticket.id)][str(order.status)]['sales']  += order_ticket.quantity * ticket.price
     return render_template('gentelella/admin/event/tickets/tickets.html', event=event, event_id=event_id,
                            orders_summary=orders_summary, tickets_summary=tickets_summary)
 
@@ -104,9 +112,36 @@ def display_orders(event_id):
 @event_ticket_sales.route('/attendees/')
 def display_attendees(event_id):
     event = DataGetter.get_event(event_id)
-    orders = TicketingManager.get_orders(event_id, status='completed')
+    orders = TicketingManager.get_orders(event_id)
+    holders = []
+    for order in orders:
+        for holder in order.ticket_holders:
+            discount = TicketingManager.get_discount_code(event_id, order.discount_code_id)
+            order_holder={}
+            order_holder['order_invoice'] = order.get_invoice_number()
+            order_holder['order_url'] = url_for('ticketing.view_order_after_payment', order_identifier=order.identifier) \
+                                        if order.status == 'completed' else url_for('ticketing.show_transaction_error', \
+                                        order_identifier=order.identifier)
+            order_holder['paid_via'] = order.paid_via
+            order_holder['status'] = order.status
+            order_holder['completed_at'] = order.completed_at
+            order_holder['created_at'] = order.created_at
+            order_holder['ticket_name'] = holder.ticket.name 
+            order_holder['firstname'] = holder.firstname
+            order_holder['lastname'] = holder.lastname
+            order_holder['email'] = holder.email
+            order_holder['ticket_name'] = holder.ticket.name
+            order_holder['ticket_price'] = holder.ticket.price
+            if discount and str(holder.ticket.id) in discount.tickets.split(","):
+                if discount.type == "amount" : 
+                    order_holder['ticket_price'] = order_holder['ticket_price'] - discount.value
+                else:
+                    order_holder['ticket_price'] = order_holder['ticket_price'] - (order_holder['ticket_price'] \
+                                                    * discount.value / 100.0 )
+            order_holder['checked_in'] = holder.checked_in
+            holders.append(order_holder)
     return render_template('gentelella/admin/event/tickets/attendees.html', event=event,
-                           event_id=event_id, orders=orders)
+                           event_id=event_id, holders=holders)
 
 
 @event_ticket_sales.route('/add-order/', methods=('GET', 'POST'))


Test patch: