Merge pull request #14920 from codingCoffee/split_issue
Split a given Issue into 2
This commit is contained in:
commit
218f2f841e
@ -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")
|
||||
$(`<button class="btn btn-xs btn-link btn-add-to-kb text-muted hidden-xs btn-split-issue pull-right" style="display:inline-block; margin-right: 5px">
|
||||
${split_issue}
|
||||
</button>`)
|
||||
.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: <a href="${result}/desk#Form/Issue/${r.message}">${r.message}</a>`)
|
||||
frm.reload_doc();
|
||||
dialog.hide();
|
||||
});
|
||||
}
|
||||
});
|
||||
dialog.show()
|
||||
})
|
||||
frm.timeline.wrapper.data("split-issue-event-attached", true)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user