Skip to content

Commit baeb6af

Browse files
pratikb64mergify[bot]
authored andcommitted
fix: last response calculation
(cherry picked from commit d8e0d42)
1 parent fd7489f commit baeb6af

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

crm/fcrm/doctype/crm_service_level_agreement/crm_service_level_agreement.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def set_rolling_responses(self, doc: Document):
116116
)
117117
elif doc.communication_status != self.get_default_priority():
118118
current_time = now_datetime()
119-
doc.last_response_time = self.calc_elapsed_time(doc.last_responded_on, current_time)
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)
120121
doc.last_responded_on = current_time
121122
is_failed = self.is_rolling_response_failed(doc)
122123
doc.append(
@@ -289,6 +290,24 @@ def calc_elapsed_time(self, start_time, end_time) -> float:
289290

290291
return total_seconds
291292

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+
292311
def get_priorities(self):
293312
"""
294313
Return priorities related info as a dict. With `priority` as key

0 commit comments

Comments
 (0)