From 769054e00d9f1834b9fc129f0d64ab96f8e6b762 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 16 Jul 2018 17:08:30 +0530 Subject: [PATCH] Split a given Issue into 2 Bugs encountered: Once the dialog pops up, filling in the subject and pressing RETURN doesn't work. It fails to read the subject. The primary button needs to be clicked on. This is a generic issue, not related to this PR Behaviour: -[x] Add button on communication to split thread -[x] Popup asks for new subject -[x] Copy "Customer", "Sender" and other relevant fields to this issue -[x] Move thread and replies to new issue fixes #14600 --- erpnext/support/doctype/issue/issue.js | 38 ++++++++++++++++++++++++-- erpnext/support/doctype/issue/issue.py | 16 +++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/erpnext/support/doctype/issue/issue.js b/erpnext/support/doctype/issue/issue.js index 77c59f4edc..72a226e0cd 100644 --- a/erpnext/support/doctype/issue/issue.js +++ b/erpnext/support/doctype/issue/issue.js @@ -1,9 +1,9 @@ frappe.ui.form.on("Issue", { - "onload": function(frm) { + onload: function(frm) { frm.email_field = "raised_by"; }, - "refresh": function(frm) { + refresh: function(frm) { if(frm.doc.status!=="Closed") { frm.add_custom_button(__("Close"), function() { frm.set_value("status", "Closed"); @@ -33,5 +33,39 @@ frappe.ui.form.on("Issue", { frappe.set_route('Form', 'Help Article', doc.name); }); } + + if (!frm.timeline.wrapper.find('.btn-split-issue').length) { + let split_issue = __("Split Issue") + $(``) + .appendTo(frm.timeline.wrapper.find('.comment-header .asset-details:not([data-communication-type="Comment"])')) + if (!frm.timeline.wrapper.data("split-issue-event-attached")){ + frm.timeline.wrapper.on('click', '.btn-split-issue', (e) => { + var dialog = new frappe.ui.Dialog({ + title: __("Split Issue"), + fields: [ + {fieldname: 'subject', fieldtype: 'Data', reqd:1, label: __('Subject'), description: __('All communications including and above this shall be moved into the new Issue')} + ], + primary_action_label: __("Split"), + primary_action: function() { + frm.call("split_issue", { + subject: dialog.fields_dict.subject.value, + communication_id: e.currentTarget.closest(".timeline-item").getAttribute("data-name") + }, (r) => { + let url = window.location.href + let arr = url.split("/"); + let result = arr[0] + "//" + arr[2] + frappe.msgprint(`New issue created: ${r.message}`) + frm.reload_doc(); + dialog.hide(); + }); + } + }); + dialog.show() + }) + frm.timeline.wrapper.data("split-issue-event-attached", true) + } + } } }); diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py index ef54b20efc..4eec3e0735 100644 --- a/erpnext/support/doctype/issue/issue.py +++ b/erpnext/support/doctype/issue/issue.py @@ -81,6 +81,22 @@ class Issue(Document): self.db_set("description", "") + def split_issue(self, subject, communication_id): + # Bug: Pressing enter doesn't send subject + from copy import deepcopy + replicated_issue = deepcopy(self) + replicated_issue.subject = subject + frappe.get_doc(replicated_issue).insert() + # Replicate linked Communications + # todo get all communications in timeline before this, and modify them to append them to new doc + comm_to_split_from = frappe.get_doc("Communication", communication_id) + communications = frappe.get_all("Communication", filters={"reference_name": 'ISS-00001', "reference_doctype": "Issue", "creation": ('>=', comm_to_split_from.creation)}) + for communication in communications: + doc = frappe.get_doc("Communication", communication.name) + doc.reference_name = replicated_issue.name + doc.save() + return replicated_issue.name + def get_list_context(context=None): return { "title": _("Issues"),