@@ -98,8 +98,10 @@ def set_first_response_time(self, doc: Document):
9898 end_at = doc .first_responded_on
9999 if not start_at or not end_at :
100100 return
101- doc .first_response_time = self .calc_elapsed_time (start_at , end_at )
102- if not doc .last_response_time :
101+ if not doc .first_response_time :
102+ doc .first_response_time = self .calc_elapsed_time (start_at , end_at )
103+
104+ if not doc .last_response_time and doc .first_response_time :
103105 doc .last_response_time = doc .first_response_time
104106
105107 def set_rolling_responses (self , doc : Document ):
@@ -116,8 +118,7 @@ def set_rolling_responses(self, doc: Document):
116118 )
117119 elif doc .communication_status != self .get_default_priority ():
118120 current_time = now_datetime ()
119- customer_reply_time = self .get_last_customer_reply (doc ) or doc .last_responded_on
120- doc .last_response_time = self .calc_elapsed_time (customer_reply_time , current_time )
121+ doc .last_response_time = self .calc_elapsed_time (doc .last_responded_on , current_time )
121122 doc .last_responded_on = current_time
122123 is_failed = self .is_rolling_response_failed (doc )
123124 doc .append (
@@ -188,15 +189,15 @@ def handle_rolling_sla_status(self, doc: Document):
188189 if not self .rolling_responses or len (doc .rolling_responses ) == 0 :
189190 return
190191
191- # Check both the current cycle and past rolling response entries
192- has_past_failure = any ( r . status == "Failed" for r in doc . rolling_responses )
193-
194- if has_past_failure or self .is_rolling_response_failed ( doc ):
195- doc . sla_status = "Failed"
196- elif doc . communication_status == self . get_default_priority ():
197- doc . sla_status = "Rolling Response Due"
198- else :
199- doc .sla_status = "Fulfilled"
192+ is_failed = self . is_rolling_response_failed ( doc )
193+ options = {
194+ "Fulfilled" : True ,
195+ "Rolling Response Due" : doc . communication_status == self .get_default_priority (),
196+ "Failed" : is_failed ,
197+ }
198+ for status in options :
199+ if options [ status ] :
200+ doc .sla_status = status
200201
201202 def is_rolling_response_failed (self , doc : Document ):
202203 if not doc .response_by :
@@ -290,24 +291,6 @@ def calc_elapsed_time(self, start_time, end_time) -> float:
290291
291292 return total_seconds
292293
293- def get_last_customer_reply (self , doc : Document ):
294- """Get the communication_date of the last received (customer) message"""
295- result = frappe .get_all (
296- "Communication" ,
297- filters = {
298- "reference_doctype" : doc .doctype ,
299- "reference_name" : doc .name ,
300- "sent_or_received" : "Received" ,
301- "communication_type" : "Communication" ,
302- },
303- fields = ["communication_date" ],
304- order_by = "communication_date desc" ,
305- limit = 1 ,
306- )
307- if result :
308- return get_datetime (result [0 ].communication_date )
309- return None
310-
311294 def get_priorities (self ):
312295 """
313296 Return priorities related info as a dict. With `priority` as key
0 commit comments