From 7a7a39d567ddc39c9a764f497b53339fb0485b01 Mon Sep 17 00:00:00 2001 From: Sam Splunks <72095718+samsplunks@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:16:24 +0000 Subject: [PATCH] Extracting previous ticket status from latest follow-up with new_status set --- helpdesk/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/helpdesk/models.py b/helpdesk/models.py index 167745fc..4409d901 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -1007,16 +1007,24 @@ class FollowUp(models.Model): def time_spent_calculation(self): "Returns timedelta according to rules settings." - # extract parameters from previous follow-up or ticket + # extract earliest from previous follow-up or ticket try: prev_fup_qs = self.ticket.followup_set.all() if self.id: prev_fup_qs = prev_fup_qs.filter(id__lt=self.id) prev_fup = prev_fup_qs.latest("date") earliest = prev_fup.date - prev_status = prev_fup.new_status except ObjectDoesNotExist: 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 # latest time is current follow-up date