improve multiple add dialog, populate parent's depends on with child tasks (#13142)
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index 76c34db..e418845 100644
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -69,6 +69,7 @@
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 @@
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 @@
@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()
diff --git a/erpnext/projects/doctype/task/task_tree.js b/erpnext/projects/doctype/task/task_tree.js
index 3ff00f6..d1d872f 100644
--- a/erpnext/projects/doctype/task/task_tree.js
+++ b/erpnext/projects/doctype/task/task_tree.js
@@ -44,23 +44,39 @@
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();
}
}
],