Skip to content

Commit a793fbb

Browse files
fix_admin_sales_api
1 parent a937775 commit a793fbb

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

app/api/admin_sales/events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from marshmallow_jsonapi.flask import Schema
33
from flask_rest_jsonapi import ResourceList
44

5+
from app.api.helpers.utilities import dasherize
56
from app.api.bootstrap import api
67
from app.models import db
78
from app.models.event import Event
@@ -23,6 +24,7 @@ class AdminSalesByEventsSchema(Schema):
2324
class Meta:
2425
type_ = 'admin-sales-by-events'
2526
self_view = 'v1.admin_sales_by_events'
27+
inflect = dasherize
2628

2729
id = fields.String()
2830
name = fields.String()

app/api/admin_sales/locations.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from marshmallow_jsonapi.flask import Schema
33
from flask_rest_jsonapi import ResourceList
44
from sqlalchemy import func
5+
from app.api.helpers.utilities import dasherize
56

67
from app.api.bootstrap import api
78
from app.models import db
@@ -34,6 +35,7 @@ class AdminSalesByLocationSchema(Schema):
3435
class Meta:
3536
type_ = 'admin-sales-by-location'
3637
self_view = 'v1.admin_sales_by_location'
38+
inflect = dasherize
3739

3840
id = fields.String()
3941
location_name = fields.String()
@@ -63,9 +65,12 @@ class AdminSalesByLocationList(ResourceList):
6365
"""
6466

6567
def query(self, _):
66-
locations = self.session.query(Event.location_name) \
67-
.group_by(Event.location_name) \
68-
.cte()
68+
locations = self.session.query(
69+
Event.location_name,
70+
Event.location_name.label('id')) \
71+
.group_by(Event.location_name) \
72+
.filter(Event.location_name.isnot(None)) \
73+
.cte()
6974

7075
pending = sales_per_location_by_status('pending')
7176
completed = sales_per_location_by_status('completed')

app/api/admin_sales/organizer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from marshmallow_jsonapi.flask import Schema
33
from flask_rest_jsonapi import ResourceList
44

5+
from app.api.helpers.utilities import dasherize
56
from app.api.bootstrap import api
67
from app.models import db
78
from app.models.event import Event
@@ -25,6 +26,7 @@ class AdminSalesByOrganizersSchema(Schema):
2526
class Meta:
2627
type_ = 'admin-sales-by-organizers'
2728
self_view = 'v1.admin_sales_by_organizers'
29+
inflect = dasherize
2830

2931
id = fields.String()
3032
first_name = fields.String()

app/api/admin_sales/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def status_summary(orders, status):
1111
"""
1212
return {
1313
'sales_total': sum([o.amount for o in orders if o.status == status]),
14-
'ticket_count': sum([o.tickets_count for o in orders])
14+
'ticket_count': sum([o.tickets_count for o in orders if o.status == status])
1515
}
1616

1717

0 commit comments

Comments
 (0)