Repository: fossasia/open-event-server

Issue:
Overview of ticket income shows incorrect number
Comparing numbers in the ticket sales of organizers and in the admin ticket dashboard shows different numbers. Numbers in the specific event ticket dashboard are correct.

![screenshot from 2017-01-19 13-26-05](https://cloud.githubusercontent.com/assets/1583873/22106840/fd61506c-de4a-11e6-9676-721528644717.png)



Discussion:
I'd like to do this


Resolving patch:
diff --git a/app/views/super_admin/sales.py b/app/views/super_admin/sales.py
--- a/app/views/super_admin/sales.py
+++ b/app/views/super_admin/sales.py
@@ -332,26 +332,36 @@ def sales_by_events_view(path):
         orders_summary[str(order.status)]['total_sales'] += forex(order.event.payment_currency,
                                                                   display_currency, order.amount)
         for order_ticket in order.tickets:
+            discount = TicketingManager.get_discount_code(order.event_id, order.discount_code_id)
             orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity
             ticket = CachedGetter.get_ticket(order_ticket.ticket_id)
             tickets_summary_event_wise[str(order.event_id)][str(order.status)]['tickets_count'] \
                 += order_ticket.quantity
             tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['tickets_count'] \
                 += order_ticket.quantity
-            tickets_summary_location_wise[unicode(order
-                                              .event.searchable_location_name)][str(order
-                                                                                    .status)]['tickets_count'] \
+            tickets_summary_location_wise[unicode(order.event.searchable_location_name)][str(order.status)]['tickets_count'] \
                 += order_ticket.quantity
 
             if order.paid_via != 'free' and order.amount > 0:
-                tickets_summary_event_wise[str(order.event_id)][str(order.status)]['sales'] += \
-                    order_ticket.quantity * ticket.price
-                tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['sales'] += \
-                    order_ticket.quantity * ticket.price
-                tickets_summary_location_wise[str(order.event.
-                                                  searchable_location_name)][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_event_wise[str(order.event_id)][str(order.status)]['sales'] += order_ticket.quantity * (ticket.price - \
+                                                                                        discount.value)
+                        tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['sales'] += order_ticket.quantity * (ticket.price - \
+                                                                                        discount.value)
+                        tickets_summary_location_wise[str(order.event.searchable_location_name)][str(order.status)]['sales'] += order_ticket.quantity * (ticket.price - \
+                                                                                        discount.value)
+                    else:
+                        tickets_summary_event_wise[str(order.event_id)][str(order.status)]['sales'] += order_ticket.quantity * (ticket.price - \
+                                                                                        discount.value * ticket.price / 100.0)
+                        tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['sales'] += order_ticket.quantity * (ticket.price - \
+                                                                                        discount.value * ticket.price / 100.0)
+                        tickets_summary_location_wise[str(order.event.searchable_location_name)][str(order.status)]['sales'] += order_ticket.quantity * (ticket.price - \
+                                                                                        discount.value * ticket.price / 100.0)
+                else:
+                    tickets_summary_event_wise[str(order.event_id)][str(order.status)]['sales']  += order_ticket.quantity * ticket.price
+                    tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['sales']  += order_ticket.quantity * ticket.price
+                    tickets_summary_location_wise[str(order.event.searchable_location_name)][str(order.status)]['sales']  += order_ticket.quantity * ticket.price
 
     if path == 'events' or path == 'discounted-events':
         return render_template('gentelella/admin/super_admin/sales/by_events.html',


Test patch: