fix(patch): add patch for setting issue metrics (#22296)

* patch: set issue metrics in Issue documents

* fix: commit after every 100 records
This commit is contained in:
Rucha Mahabal 2020-06-18 15:38:43 +05:30 committed by GitHub
parent 34d2bfbb3e
commit a529d71ca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -699,3 +699,4 @@ erpnext.patches.v13_0.delete_old_purchase_reports
erpnext.patches.v12_0.set_italian_import_supplier_invoice_permissions
erpnext.patches.v13_0.update_sla_enhancements
erpnext.patches.v12_0.update_address_template_for_india
erpnext.patches.v13_0.update_issue_metrics

View File

@ -0,0 +1,33 @@
from __future__ import unicode_literals
import frappe
from frappe.core.doctype.communication.communication import set_avg_response_time
from erpnext.support.doctype.issue.issue import set_resolution_time, set_user_resolution_time
def execute():
if frappe.db.exists('DocType', 'Issue'):
frappe.reload_doctype('Issue')
count = 0
for parent in frappe.get_all('Issue', order_by='creation desc'):
parent_doc = frappe.get_doc('Issue', parent.name)
communication = frappe.get_all('Communication', filters={
'reference_doctype': 'Issue',
'reference_name': parent.name,
'communication_medium': 'Email',
'sent_or_received': 'Sent'
}, order_by = 'creation asc', limit=1)
if communication:
communication_doc = frappe.get_doc('Communication', communication[0].name)
set_avg_response_time(parent_doc, communication_doc)
if parent_doc.status in ['Closed', 'Resolved']:
set_resolution_time(parent_doc)
set_user_resolution_time(parent_doc)
# commit after every 100 records
count += 1
if count % 100 == 0:
frappe.db.commit()