From defe1b2eef0da56261673d0c2887c391dce97037 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Sat, 18 May 2019 13:37:00 +0530 Subject: [PATCH] fix: miscellaneous changes --- .../doctype/communication/communication.js | 2 +- frappe/desk/doctype/todo/todo.py | 7 +- frappe/desk/form/load.py | 3 +- frappe/patches.txt | 2 - .../move_timeline_links_to_dynamic_links.py | 85 ++++++------------- 5 files changed, 35 insertions(+), 64 deletions(-) diff --git a/frappe/core/doctype/communication/communication.js b/frappe/core/doctype/communication/communication.js index 4734f6a11a..180ba8d25c 100644 --- a/frappe/core/doctype/communication/communication.js +++ b/frappe/core/doctype/communication/communication.js @@ -43,7 +43,7 @@ frappe.ui.form.on("Communication", { }); } - frm.add_custom_button(__("Add Primary link"), function() { + frm.add_custom_button(__("Change Reference Link"), function() { frm.trigger('show_relink_dialog'); }, "Links"); diff --git a/frappe/desk/doctype/todo/todo.py b/frappe/desk/doctype/todo/todo.py index 45c3874806..051d26d7be 100644 --- a/frappe/desk/doctype/todo/todo.py +++ b/frappe/desk/doctype/todo/todo.py @@ -43,8 +43,11 @@ class ToDo(Document): def on_trash(self): # unlink todo from linked comments - frappe.db.sql("""update `tabCommunication` set link_doctype=null, link_name=null - where link_doctype=%(doctype)s and link_name=%(name)s""", {"doctype": self.doctype, "name": self.name}) + frappe.db.sql(""" + delete from `tabDynamic Link` + where link_doctype=%(doctype)s and link_name=%(name)s""", { + "doctype": self.doctype, "name": self.name + }) self.update_in_reference() diff --git a/frappe/desk/form/load.py b/frappe/desk/form/load.py index 102972f331..2985a8858e 100644 --- a/frappe/desk/form/load.py +++ b/frappe/desk/form/load.py @@ -166,8 +166,7 @@ def get_communication_data(doctype, name, start=0, limit=20, after=None, fields= `tabCommunication`.sender, `tabCommunication`.sender_full_name, `tabCommunication`.cc, `tabCommunication`.bcc, `tabCommunication`.creation, `tabCommunication`.subject, `tabCommunication`.delivery_status, `tabCommunication`._liked_by, `tabCommunication`.reference_doctype, `tabCommunication`.reference_name, - `tabCommunication`.link_doctype, `tabCommunication`.link_name, `tabCommunication`.read_by_recipient, - `tabCommunication`.rating + `tabCommunication`.read_by_recipient, `tabCommunication`.rating ''' conditions = ''' diff --git a/frappe/patches.txt b/frappe/patches.txt index 15f9ad8c73..911e793687 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -241,6 +241,4 @@ frappe.patches.v12_0.reset_home_settings frappe.patches.v12_0.update_print_format_type frappe.patches.v11_0.remove_doctype_user_permissions_for_page_and_report #2019-05-01 frappe.patches.v12_0.remove_feedback_rating -execute:frappe.reload_doc('core', 'doctype', 'communication') -execute:frappe.reload_doc('core', 'doctype', 'dynamic_link') frappe.patches.v12_0.move_timeline_links_to_dynamic_links \ No newline at end of file diff --git a/frappe/patches/v12_0/move_timeline_links_to_dynamic_links.py b/frappe/patches/v12_0/move_timeline_links_to_dynamic_links.py index d8d249ae73..9d6cfffb84 100644 --- a/frappe/patches/v12_0/move_timeline_links_to_dynamic_links.py +++ b/frappe/patches/v12_0/move_timeline_links_to_dynamic_links.py @@ -3,66 +3,37 @@ from __future__ import unicode_literals import frappe def execute(): - comm_lists = [] - for communication in frappe.db.sql(""" - Select - `tabCommunication`.name, `tabCommunication`.creation, `tabCommunication`.modified, - `tabCommunication`.modified_by,`tabCommunication`.timeline_doctype, `tabCommunication`.timeline_name, - `tabCommunication`.link_doctype, `tabCommunication`.link_name - from `tabCommunication` - where `tabCommunication`.communication_medium='Email' - """, as_dict=True): + frappe.reload_doc('core', 'doctype', 'communication') + + sql_query = """INSERT INTO `tabDynamic Link` + (`idx`, `name`, `parentfield`, `parenttype`, `parent`, `link_doctype`, `link_name`, `creation`, + `modified`, `modified_by`) + VALUES """ + + communications = frappe.db.sql(""" + Select + `tabCommunication`.name, `tabCommunication`.creation, `tabCommunication`.modified, + `tabCommunication`.modified_by,`tabCommunication`.timeline_doctype, `tabCommunication`.timeline_name, + `tabCommunication`.link_doctype, `tabCommunication`.link_name + from `tabCommunication` + where `tabCommunication`.communication_medium='Email' + """, as_dict=True) + + for communication in communications: counter = 1 if communication.timeline_doctype and communication.timeline_name: - comm_lists.append( - { - "idx": counter, - "name": frappe.generate_hash(length=10), - "parentfield": "timeline_links", - "parenttype": "Communication", - "parent": communication.name, - "link_doctype": communication.timeline_doctype, - "link_name": communication.timeline_name, - "creation": communication.creation, - "modified": communication.modified, - "modified_by": communication.modified_by - } - ) + sql_query += str(( + counter, frappe.generate_hash(length=10), "timeline_links", "Communication", communication.name, + communication.timeline_doctype, communication.timeline_name, communication.creation, + communication.modified, communication.modified_by + )) + """, """ counter += 1 if communication.link_doctype and communication.link_name: - comm_lists.append( - { - "idx": counter, - "name": frappe.generate_hash(length=10), - "parentfield": "timeline_links", - "parenttype": "Communication", - "parent": communication.name, - "link_doctype": communication.link_doctype, - "link_name": communication.link_name, - "creation": communication.creation, - "modified": communication.modified, - "modified_by": communication.modified_by - } - ) + sql_query += str(( + counter, frappe.generate_hash(length=10), "timeline_links", "Communication", communication.name, + communication.link_doctype, communication.link_name, communication.creation, + communication.modified, communication.modified_by + )) + """, """ - for comm_list in comm_lists: - frappe.db.sql(""" - INSERT INTO `tabDynamic Link` - (`idx`, `name`, `parentfield`, `parenttype`, `parent`, `link_doctype`, `link_name`, `creation`, - `modified`, `modified_by`) - VALUES - (%(idx)s, %(name)s, %(parentfield)s, %(parenttype)s, %(parent)s, %(link_doctype)s, %(link_name)s,%(creation)s, - %(modified)s, %(modified_by)s) - """,{ - "idx": comm_list.get("idx"), - "name": comm_list.get("name"), - "parentfield": comm_list.get("parentfield"), - "parenttype": comm_list.get("parenttype"), - "parent": comm_list.get("parent"), - "link_doctype": comm_list.get("link_doctype"), - "link_name": comm_list.get("link_name"), - "creation": comm_list.get("creation"), - "modified": comm_list.get("modified"), - "modified_by": comm_list.get("modified_by") - }) \ No newline at end of file + frappe.db.sql(sql_query)