Skip to content

Commit

Permalink
Activity Log Patch fix (#4580)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashah115 authored and netchampfaris committed Dec 7, 2017
1 parent a247dfe commit e6f294b
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions frappe/patches/v9_1/move_feed_to_activity_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,12 @@ def execute():
frappe.reload_doc("core", "doctype", "communication")
frappe.reload_doc("core", "doctype", "activity_log")

communication_data = frappe.get_all('Communication', filters= {'comment_type': 'Updated'})
activity_log_fields = frappe.get_meta('Activity Log').fields

for d in communication_data:
try:
communication_doc = frappe.get_doc('Communication', d)

activity_data = {'doctype': 'Activity Log'}
for field in activity_log_fields:
if communication_doc.get(field.fieldname):
if field.fieldname == "reference_name":
if not frappe.db.exists(communication_doc.get("reference_doctype"), communication_doc.get("reference_name")):
continue
if field.fieldname == "timeline_name":
if not frappe.db.exists(communication_doc.get("timeline_doctype"), communication_doc.get("timeline_name")):
continue

activity_data[field.fieldname] = communication_doc.get_value(field.fieldname)

activity_doc = frappe.get_doc(activity_data)
activity_doc.insert()

frappe.db.sql("""update `tabActivity Log` set creation = %s,\
modified = %s where name = %s""", (communication_doc.creation,communication_doc.modified,activity_doc.name))

frappe.db.sql("""delete from `tabCommunication` where name='{0}'""".format(communication_doc.name))

except frappe.LinkValidationError:
pass
frappe.db.sql("""insert into `tabActivity Log` (name, owner, modified, creation, status, communication_date,
reference_doctype, reference_name, timeline_doctype, timeline_name, link_doctype, link_name, subject, content, user)
select name, owner, modified, creation, status, communication_date,
reference_doctype, reference_name, timeline_doctype, timeline_name, link_doctype, link_name, subject, content, user
from `tabCommunication`
where comment_type = 'Updated'""")

frappe.db.sql("""delete from `tabCommunication` where comment_type = 'Updated'""")
frappe.delete_doc("DocType", "Authentication Log")

0 comments on commit e6f294b

Please sign in to comment.