Skip to content

Commit

Permalink
moved some methods from communication.py to utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyashah115 committed Nov 21, 2017
1 parent 8cd1469 commit a813b27
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 76 deletions.
50 changes: 25 additions & 25 deletions frappe/core/doctype/activity_log/activity_log.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_14",
"fieldname": "column_break_7",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
Expand Down Expand Up @@ -414,25 +414,22 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "__user",
"fieldname": "user",
"fieldtype": "Link",
"fieldname": "column_break_14",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "User",
"length": 0,
"no_copy": 0,
"options": "User",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
Expand All @@ -446,18 +443,19 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "full_name",
"fieldtype": "Data",
"fieldname": "timeline_doctype",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Full Name",
"label": "Timeline DocType",
"length": 0,
"no_copy": 0,
"options": "DocType",
"permlevel": 0,
"precision": "",
"print_hide": 0,
Expand All @@ -476,17 +474,19 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_27",
"fieldtype": "Column Break",
"fieldname": "timeline_name",
"fieldtype": "Dynamic Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Timeline Name",
"length": 0,
"no_copy": 0,
"options": "timeline_doctype",
"permlevel": 0,
"precision": "",
"print_hide": 0,
Expand Down Expand Up @@ -567,24 +567,25 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "timeline_doctype",
"default": "__user",
"fieldname": "user",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Timeline DocType",
"label": "User",
"length": 0,
"no_copy": 0,
"options": "DocType",
"options": "User",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
Expand All @@ -598,19 +599,18 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "timeline_name",
"fieldtype": "Dynamic Link",
"fieldname": "full_name",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Timeline Name",
"label": "Full Name",
"length": 0,
"no_copy": 0,
"options": "timeline_doctype",
"permlevel": 0,
"precision": "",
"print_hide": 0,
Expand All @@ -635,7 +635,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-11-12 17:28:41.745051",
"modified": "2017-11-21 12:39:23.659308",
"modified_by": "Administrator",
"module": "Core",
"name": "Activity Log",
Expand Down
8 changes: 8 additions & 0 deletions frappe/core/doctype/activity_log/activity_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from frappe import _
from frappe.utils import get_fullname, now
from frappe.model.document import Document
from frappe.core.utils import get_parent_doc, set_timeline_doc
import frappe

class ActivityLog(Document):
Expand All @@ -15,6 +16,7 @@ def before_insert(self):

def validate(self):
self.set_status()
set_timeline_doc(self)

def set_status(self):
if not self.is_new():
Expand All @@ -26,6 +28,12 @@ def set_status(self):
def on_trash(self): # pylint: disable=no-self-use
frappe.throw(_("Sorry! You cannot delete auto-generated comments"))

def on_doctype_update():
"""Add indexes in `tabActivity Log`"""
frappe.db.add_index("Activity Log", ["reference_doctype", "reference_name"])
frappe.db.add_index("Activity Log", ["timeline_doctype", "timeline_name"])
frappe.db.add_index("Activity Log", ["link_doctype", "link_name"])

def add_authentication_log(subject, user, operation="Login", status="Success"):
frappe.get_doc({
"doctype": "Activity Log",
Expand Down
60 changes: 30 additions & 30 deletions frappe/core/doctype/communication/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def validate(self):
self.set_status()
self.set_sender_full_name()
validate_email(self)
self.set_timeline_doc()
set_timeline_doc(self)

def after_insert(self):
if not (self.reference_doctype and self.reference_name):
Expand Down Expand Up @@ -149,35 +149,6 @@ def set_sender_full_name(self):
self.sender = sender_email
self.sender_full_name = sender_name or get_fullname(frappe.session.user) if frappe.session.user!='Administrator' else None

def get_parent_doc(self):
"""Returns document of `reference_doctype`, `reference_doctype`"""
if not hasattr(self, "parent_doc"):
if self.reference_doctype and self.reference_name:
self.parent_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
else:
self.parent_doc = None
return self.parent_doc

def set_timeline_doc(self):
"""Set timeline_doctype and timeline_name"""
parent_doc = self.get_parent_doc()
if (self.timeline_doctype and self.timeline_name) or not parent_doc:
return

timeline_field = parent_doc.meta.timeline_field
if not timeline_field:
return

doctype = parent_doc.meta.get_link_doctype(timeline_field)
name = parent_doc.get(timeline_field)

if doctype and name:
self.timeline_doctype = doctype
self.timeline_name = name

else:
return

def send(self, print_html=None, print_format=None, attachments=None,
send_me_a_copy=False, recipients=None):
"""Send communication via Email.
Expand Down Expand Up @@ -253,6 +224,35 @@ def set_delivery_status(self, commit=False):
if commit:
frappe.db.commit()

def get_parent_doc(doc):
"""Returns document of `reference_doctype`, `reference_doctype`"""
if not hasattr(doc, "parent_doc"):
if doc.reference_doctype and doc.reference_name:
doc.parent_doc = frappe.get_doc(doc.reference_doctype, doc.reference_name)
else:
doc.parent_doc = None
return doc.parent_doc

def set_timeline_doc(doc):
"""Set timeline_doctype and timeline_name"""
parent_doc = get_parent_doc(doc)
if (doc.timeline_doctype and doc.timeline_name) or not parent_doc:
return

timeline_field = parent_doc.meta.timeline_field
if not timeline_field:
return

doctype = parent_doc.meta.get_link_doctype(timeline_field)
name = parent_doc.get(timeline_field)

if doctype and name:
doc.timeline_doctype = doctype
doc.timeline_name = name

else:
return

def on_doctype_update():
"""Add indexes in `tabCommunication`"""
frappe.db.add_index("Communication", ["reference_doctype", "reference_name"])
Expand Down
8 changes: 5 additions & 3 deletions frappe/core/doctype/communication/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import frappe
import json
from email.utils import formataddr
from frappe.core.utils import get_parent_doc
from frappe.utils import (get_url, get_formatted_email, cint,
validate_email_add, split_emails, time_diff_in_seconds, parse_addr)
from frappe.utils.file_manager import get_file
Expand Down Expand Up @@ -172,7 +173,8 @@ def _notify(doc, print_html=None, print_format=None, attachments=None,

def update_parent_mins_to_first_response(doc):
"""Update mins_to_first_communication of parent document based on who is replying."""
parent = doc.get_parent_doc()

parent = get_parent_doc(doc)
if not parent:
return

Expand Down Expand Up @@ -441,7 +443,7 @@ def filter_email_list(doc, email_list, exclude, is_cc=False, is_bcc=False):
return filtered

def get_owner_email(doc):
owner = doc.get_parent_doc().owner
owner = get_parent_doc(doc).owner
return get_formatted_email(owner) or owner

def get_assignees(doc):
Expand All @@ -460,7 +462,7 @@ def get_attach_link(doc, print_format):
"doctype": doc.reference_doctype,
"name": doc.reference_name,
"print_format": print_format,
"key": doc.get_parent_doc().get_signature()
"key": get_parent_doc(doc).get_signature()
})

def sendmail(communication_name, print_html=None, print_format=None, attachments=None,
Expand Down
22 changes: 11 additions & 11 deletions frappe/model/delete_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,6 @@ def delete_dynamic_links(doctype, name):
and reference_doctype=%s
and reference_name=%s""", (doctype, name))

# unlink activity_log
frappe.db.sql("""update `tabActivity Log`
set reference_doctype=null, reference_name=null
where
reference_doctype=%s
and reference_name=%s""", (doctype, name))

# unlink secondary references
frappe.db.sql("""update `tabCommunication`
set link_doctype=null, link_name=null
Expand All @@ -283,10 +276,17 @@ def delete_dynamic_links(doctype, name):
set timeline_doctype=null, timeline_name=null
where timeline_doctype=%s and timeline_name=%s""", (doctype, name))

# unlink feed
# frappe.db.sql("""update `tabActivity Log`
# set timeline_doctype=null, timeline_name=null
# where timeline_doctype=%s and timeline_name=%s""", (doctype, name))
# unlink activity_log reference_doctype
frappe.db.sql("""update `tabActivity Log`
set reference_doctype=null, reference_name=null
where
reference_doctype=%s
and reference_name=%s""", (doctype, name))

# unlink activity_log timeline_doctype
frappe.db.sql("""update `tabActivity Log`
set timeline_doctype=null, timeline_name=null
where timeline_doctype=%s and timeline_name=%s""", (doctype, name))

def insert_feed(doc):
from frappe.utils import get_fullname
Expand Down
2 changes: 1 addition & 1 deletion frappe/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,4 @@ frappe.patches.v8_x.add_bgn_xaf_xof_currencies
frappe.patches.v9_1.add_sms_sender_name_as_parameters
frappe.patches.v9_1.resave_domain_settings
frappe.patches.v9_1.revert_domain_settings
#frappe.patches.v9_1.move_feed_to_activity_log
frappe.patches.v9_1.move_feed_to_activity_log
9 changes: 3 additions & 6 deletions frappe/patches/v9_1/move_feed_to_activity_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ def execute():
if communication_doc.get(field.fieldname):
activity_data[field.fieldname] = communication_doc.get_value(field.fieldname)

activity_data['creation'] = communication_doc.creation
activity_data['modified'] = communication_doc.modified

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

# frappe.db.set_value('Activity Log', activity_doc.name, 'creation', communication_doc.creation)
# frappe.db.set_value('Activity Log', activity_doc.name, 'modified', communication_doc.modified)
frappe.db.sql("""delete from `tabCommunication` where name='{0}'""".format(communication_doc.name))
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))
frappe.delete_doc("DocType", "Authentication Log")

0 comments on commit a813b27

Please sign in to comment.