Extracting previous ticket status from latest follow-up with new_status set

This commit is contained in:
Sam Splunks 2024-02-15 16:16:24 +00:00
parent 5482d7b6df
commit 7a7a39d567

View File

@ -1007,16 +1007,24 @@ class FollowUp(models.Model):
def time_spent_calculation(self): def time_spent_calculation(self):
"Returns timedelta according to rules settings." "Returns timedelta according to rules settings."
# extract parameters from previous follow-up or ticket # extract earliest from previous follow-up or ticket
try: try:
prev_fup_qs = self.ticket.followup_set.all() prev_fup_qs = self.ticket.followup_set.all()
if self.id: if self.id:
prev_fup_qs = prev_fup_qs.filter(id__lt=self.id) prev_fup_qs = prev_fup_qs.filter(id__lt=self.id)
prev_fup = prev_fup_qs.latest("date") prev_fup = prev_fup_qs.latest("date")
earliest = prev_fup.date earliest = prev_fup.date
prev_status = prev_fup.new_status
except ObjectDoesNotExist: except ObjectDoesNotExist:
earliest = self.ticket.created earliest = self.ticket.created
# extract previous status from follow-up or ticket
try:
prev_fup_qs = self.ticket.followup_set.exclude(new_status__isnull=True)
if self.id:
prev_fup_qs = prev_fup_qs.filter(id__lt=self.id)
prev_fup = prev_fup_qs.latest("date")
prev_status = prev_fup.new_status
except ObjectDoesNotExist:
prev_status = self.ticket.status prev_status = self.ticket.status
# latest time is current follow-up date # latest time is current follow-up date