Repository: fossasia/open-event-server

Issue:
Add completed orders to order-statistics endpoint
**Is your feature request related to a problem? Please describe.**
Currently order statistics endpoint does not return completed orders.

**Describe the solution you'd like**
It should return completed orders and also fix sales accordingly. sales should return order values calculated from completed orders only.

**Additional context**
Needed in FE.



Discussion:
Working on it
@bhaveshAn please do this ASAP ... This is much needed on FE.


On Wed, 18 Jul 2018, 12:31 pm Bhavesh Anand, <notifications@github.com>
wrote:

> Working on it
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-server/issues/5134#issuecomment-405830445>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AURmGhjhq13Msy3e79p-Aiw5Ur_IunO_ks5uHt07gaJpZM4VUC71>
> .
>


Resolving patch:
diff --git a/app/api/order_statistics/events.py b/app/api/order_statistics/events.py
--- a/app/api/order_statistics/events.py
+++ b/app/api/order_statistics/events.py
@@ -46,13 +46,16 @@ def tickets_count(self, obj):
             Order.event_id == obj_id, Order.status == 'expired').scalar()
         placed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
             Order.event_id == obj_id, Order.status == 'placed').scalar()
+        completed = db.session.query(func.sum(OrderTicket.quantity.label('sum'))).join(Order.order_tickets).filter(
+            Order.event_id == obj_id, Order.status == 'completed').scalar()
         result = {
             'total': total or 0,
             'draft': draft or 0,
             'cancelled': cancelled or 0,
             'pending': pending or 0,
             'expired': expired or 0,
-            'placed': placed or 0
+            'placed': placed or 0,
+            'completed': completed or 0
         }
         return result
 
@@ -64,13 +67,15 @@ def orders_count(self, obj):
         pending = get_count(db.session.query(Order).filter(Order.event_id == obj_id, Order.status == 'pending'))
         expired = get_count(db.session.query(Order).filter(Order.event_id == obj_id, Order.status == 'expired'))
         placed = get_count(db.session.query(Order).filter(Order.event_id == obj_id, Order.status == 'placed'))
+        completed = get_count(db.session.query(Order).filter(Order.event_id == obj_id, Order.status == 'completed'))
         result = {
             'total': total or 0,
             'draft': draft or 0,
             'cancelled': cancelled or 0,
             'pending': pending or 0,
             'expired': expired or 0,
-            'placed': placed or 0
+            'placed': placed or 0,
+            'completed': completed or 0
         }
         return result
 
@@ -87,13 +92,16 @@ def sales_count(self, obj):
                                                                                Order.status == 'expired').scalar()
         placed = db.session.query(func.sum(Order.amount.label('sum'))).filter(Order.event_id == obj_id,
                                                                               Order.status == 'placed').scalar()
+        completed = db.session.query(func.sum(Order.amount.label('sum'))).filter(Order.event_id == obj_id,
+                                                                                 Order.status == 'completed').scalar()
         result = {
             'total': total or 0,
             'draft': draft or 0,
             'cancelled': cancelled or 0,
             'pending': pending or 0,
             'expired': expired or 0,
-            'placed': placed or 0
+            'placed': placed or 0,
+            'completed': completed or 0
         }
         return result
 


Test patch: