2019-01-22 12:52:20 +00:00
|
|
|
from __future__ import unicode_literals
|
2016-06-14 10:24:17 +00:00
|
|
|
import frappe
|
|
|
|
|
|
|
|
from frappe.core.doctype.communication.email import update_mins_to_first_communication
|
|
|
|
|
|
|
|
def execute():
|
|
|
|
frappe.reload_doctype('Issue')
|
|
|
|
frappe.reload_doctype('Opportunity')
|
|
|
|
|
|
|
|
for doctype in ('Issue', 'Opportunity'):
|
2016-06-14 10:57:50 +00:00
|
|
|
frappe.db.sql('update tab{0} set mins_to_first_response=0'.format(doctype))
|
|
|
|
for parent in frappe.get_all(doctype, order_by='creation desc', limit=500):
|
|
|
|
parent_doc = frappe.get_doc(doctype, parent.name)
|
2016-06-14 10:24:17 +00:00
|
|
|
for communication in frappe.get_all('Communication',
|
2016-06-14 10:57:50 +00:00
|
|
|
filters={'reference_doctype': doctype, 'reference_name': parent.name,
|
|
|
|
'communication_medium': 'Email'},
|
|
|
|
order_by = 'creation asc', limit=2):
|
2016-06-14 10:24:17 +00:00
|
|
|
|
|
|
|
communication_doc = frappe.get_doc('Communication', communication.name)
|
|
|
|
|
|
|
|
update_mins_to_first_communication(parent_doc, communication_doc)
|
|
|
|
|
|
|
|
if parent_doc.mins_to_first_response:
|
|
|
|
continue
|