[fix] treeview for tasks (#11515)

[fix] treeview for tasks
This commit is contained in:
Rushabh Mehta
2017-11-10 18:52:21 +05:30
committed by GitHub
parent a5275a1ba9
commit 4313326ba0
7 changed files with 52 additions and 49 deletions

View File

@@ -2,8 +2,8 @@
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 1,
"autoname": "field:subject",
"allow_rename": 0,
"autoname": "TASK.#####",
"beta": 0,
"creation": "2013-01-29 19:25:50",
"custom": 0,
@@ -1214,7 +1214,7 @@
"istable": 0,
"max_attachments": 5,
"menu_index": 0,
"modified": "2017-10-06 03:57:37.901446",
"modified": "2017-11-10 18:37:19.660293",
"modified_by": "Administrator",
"module": "Projects",
"name": "Task",

View File

@@ -6,7 +6,7 @@ import frappe, json
from frappe.utils import getdate, date_diff, add_days, cstr
from frappe import _, throw
from frappe.utils.nestedset import NestedSet, rebuild_tree
from frappe.utils.nestedset import NestedSet
class CircularReferenceError(frappe.ValidationError): pass
@@ -118,10 +118,10 @@ class Task(NestedSet):
end_date = self.exp_end_date or self.act_end_date
if end_date:
for task_name in frappe.db.sql("""
select name from `tabTask` as parent
where parent.project = %(project)s
select name from `tabTask` as parent
where parent.project = %(project)s
and parent.name in (
select parent from `tabTask Depends On` as child
select parent from `tabTask Depends On` as child
where child.task = %(task)s and child.project = %(project)s)
""", {'project': self.project, 'task':self.name }, as_dict=1):
task = frappe.get_doc("Task", task_name.name)
@@ -198,22 +198,28 @@ def set_tasks_as_overdue():
and `status` not in ('Closed', 'Cancelled')""")
@frappe.whitelist()
def get_children():
doctype = frappe.local.form_dict.get('doctype')
def get_children(doctype, parent, task=None, project=None, is_root=False):
conditions = ''
parent_field = 'parent_' + doctype.lower().replace(' ', '_')
parent = frappe.form_dict.get("parent") or ""
if task:
# via filters
conditions += ' and parent_task = "{0}"'.format(frappe.db.escape(task))
elif parent and not is_root:
# via expand child
conditions += ' and parent_task = "{0}"'.format(frappe.db.escape(parent))
else:
conditions += ' and ifnull(parent_task, "")=""'
if parent == "task":
parent = ""
if project:
conditions += ' and project = "{0}"'.format(frappe.db.escape(project))
tasks = frappe.db.sql("""select name as value,
subject as title,
is_group as expandable
from `tab{doctype}`
from `tabTask`
where docstatus < 2
and ifnull(`{parent_field}`,'') = %s
order by name""".format(doctype=frappe.db.escape(doctype),
parent_field=frappe.db.escape(parent_field)), (parent), as_dict=1)
{conditions}
order by name""".format(conditions=conditions), as_dict=1)
# return tasks
return tasks

View File

@@ -4,29 +4,30 @@ frappe.treeview_settings['Task'] = {
get_tree_nodes: "erpnext.projects.doctype.task.task.get_children",
add_tree_node: "erpnext.projects.doctype.task.task.add_node",
filters: [
{
fieldname: "project",
fieldtype:"Link",
options: "Project",
label: __("Project"),
},
{
fieldname: "task",
fieldtype:"Link",
options: "Task",
label: __("Task"),
get_query: function(){
get_query: function() {
return {
filters: [["Task", 'is_group', '=', 1]]
};
}
}
],
title: "Task",
breadcrumb: "Projects",
get_tree_root: false,
root_label: "task",
ignore_fields:["parent_task"],
get_label: function(node) {
return node.data.value;
},
onload: function(me){
root_label: "All Tasks",
ignore_fields: ["parent_task"],
onload: function(me) {
me.make_tree();
me.set_root = true;
},
toolbar: [
{
@@ -39,7 +40,7 @@ frappe.treeview_settings['Task'] = {
'fields': [
{'fieldname': 'tasks', 'label': 'Tasks', 'fieldtype': 'Text'},
],
primary_action: function(){
primary_action: function() {
d.hide();
return frappe.call({
method: "erpnext.projects.doctype.task.task.add_multiple_tasks",