Merge pull request #1194 from samsplunks/time_spent

Moving python time_spent calculation to database aggregation
This commit is contained in:
Christopher Broderick 2024-07-22 22:31:56 +01:00 committed by GitHub
commit 4adcc7f3d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -362,11 +362,8 @@ class Queue(models.Model):
"""Return back total time spent on the ticket. This is calculated value
based on total sum from all FollowUps
"""
total = datetime.timedelta(0)
for val in self.ticket_set.all():
if val.time_spent:
total = total + val.time_spent
return total
res = FollowUp.objects.filter(ticket__queue=self).aggregate(models.Sum('time_spent'))
return res.get('time_spent__sum', datetime.timedelta(0))
@property
def time_spent_formated(self):
@ -582,11 +579,8 @@ class Ticket(models.Model):
"""Return back total time spent on the ticket. This is calculated value
based on total sum from all FollowUps
"""
total = datetime.timedelta(0)
for val in self.followup_set.all():
if val.time_spent:
total = total + val.time_spent
return total
res = FollowUp.objects.filter(ticket=self).aggregate(models.Sum('time_spent'))
return res.get('time_spent__sum', datetime.timedelta(0))
@property
def time_spent_formated(self):