Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,19 @@ def get_staff_roles(self):
def as_dict(self):
return {c.name: getattr(self, c.name) for c in self.__table__.columns}

@property
def tickets_sold_object(self):
obj = db.session.query(Order.event_id).filter_by(event_id=self.id, status='completed').join(TicketHolder)
return obj

def calc_tickets_sold_count(self):
"""Calculate total number of tickets sold for the event"""
return db.session.query(Order.event_id).filter_by(event_id=self.id, status='completed').join(TicketHolder)\
.count()
return self.tickets_sold_object.count()

def calc_tickets_sold_prev_month(self):
"""Calculate tickets sold in the previous month"""
previous_month = datetime.datetime.now().month - 1
return self.tickets_sold.filter_by(completed_at=previous_month).count()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be self.tickets_sold_object instead of self.tickets_sold ?


def calc_total_tickets_count(self):
"""Calculate total available tickets for all types of tickets"""
Expand Down