improve multiple add dialog, populate parent's depends on with child tasks (#13142)

This commit is contained in:
Zarrar 2018-03-05 11:08:15 +05:30 committed by Nabin Hait
parent 89795c3f69
commit 4417cb0006
2 changed files with 40 additions and 13 deletions

View File

@ -69,6 +69,7 @@ class Task(NestedSet):
self.reschedule_dependent_tasks()
self.update_project()
self.unassign_todo()
self.populate_depends_on()
def unassign_todo(self):
if self.status == "Closed" or self.status == "Cancelled":
@ -137,6 +138,16 @@ class Task(NestedSet):
if project_user:
return True
def populate_depends_on(self):
if self.parent_task:
parent = frappe.get_doc('Task', self.parent_task)
parent.append("depends_on", {
"doctype": "Task Depends On",
"task": self.name,
"subject": self.subject
})
parent.save()
def on_trash(self):
if check_if_child_exists(self.name):
throw(_("Child Task exists for this Task. You can not delete this Task."))
@ -216,12 +227,12 @@ def add_node():
@frappe.whitelist()
def add_multiple_tasks(data, parent):
data = json.loads(data)['tasks']
tasks = data.split('\n')
new_doc = {'doctype': 'Task', 'parent_task': parent}
new_doc['project'] = frappe.db.get_value('Task', {"name": parent}, 'project')
data = json.loads(data)
new_doc = {'doctype': 'Task', 'parent_task': parent if parent!="All Tasks" else ""}
new_doc['project'] = frappe.db.get_value('Task', {"name": parent}, 'project') or ""
for d in tasks:
new_doc['subject'] = d
for d in data:
if not d.get("subject"): continue
new_doc['subject'] = d.get("subject")
new_task = frappe.get_doc(new_doc)
new_task.insert()

View File

@ -44,23 +44,39 @@ frappe.treeview_settings['Task'] = {
return node.expandable;
},
click: function(node) {
var d = new frappe.ui.Dialog({
'fields': [
{'fieldname': 'tasks', 'label': 'Tasks', 'fieldtype': 'Text'},
this.data = [];
const dialog = new frappe.ui.Dialog({
title: __("Add Multiple Tasks"),
fields: [
{
fieldname: "multiple_tasks", fieldtype: "Table",
in_place_edit: true, data: this.data,
get_data: () => {
return this.data;
},
fields: [{
fieldtype:'Data',
fieldname:"subject",
in_list_view: 1,
reqd: 1,
label: __("Subject")
}]
},
],
primary_action: function() {
d.hide();
dialog.hide();
return frappe.call({
method: "erpnext.projects.doctype.task.task.add_multiple_tasks",
args: {
data: d.get_values(),
data: dialog.get_values()["multiple_tasks"],
parent: node.data.value
},
callback: function() { }
});
}
},
primary_action_label: __('Create')
});
d.show();
dialog.show();
}
}
],