[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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 49 deletions

View File

@ -656,16 +656,14 @@ def get_companies():
order_by="name")] order_by="name")]
@frappe.whitelist() @frappe.whitelist()
def get_children(): def get_children(doctype, parent, company, is_root=False):
from erpnext.accounts.report.financial_statements import sort_root_accounts from erpnext.accounts.report.financial_statements import sort_root_accounts
args = frappe.local.form_dict
doctype, company = args['doctype'], args['company']
fieldname = frappe.db.escape(doctype.lower().replace(' ','_')) fieldname = frappe.db.escape(doctype.lower().replace(' ','_'))
doctype = frappe.db.escape(doctype) doctype = frappe.db.escape(doctype)
# root # root
if args['parent'] in ("Accounts", "Cost Centers"): if is_root:
fields = ", root_type, report_type, account_currency" if doctype=="Account" else "" fields = ", root_type, report_type, account_currency" if doctype=="Account" else ""
acc = frappe.db.sql(""" select acc = frappe.db.sql(""" select
name as value, is_group as expandable {fields} name as value, is_group as expandable {fields}
@ -675,7 +673,7 @@ def get_children():
order by name""".format(fields=fields, fieldname = fieldname, doctype=doctype), order by name""".format(fields=fields, fieldname = fieldname, doctype=doctype),
company, as_dict=1) company, as_dict=1)
if args["parent"]=="Accounts": if parent=="Accounts":
sort_root_accounts(acc) sort_root_accounts(acc)
else: else:
# other # other
@ -686,7 +684,7 @@ def get_children():
where ifnull(`parent_{fieldname}`,'') = %s where ifnull(`parent_{fieldname}`,'') = %s
and docstatus<2 and docstatus<2
order by name""".format(fields=fields, fieldname=fieldname, doctype=doctype), order by name""".format(fields=fields, fieldname=fieldname, doctype=doctype),
args['parent'], as_dict=1) parent, as_dict=1)
if doctype == 'Account': if doctype == 'Account':
company_currency = frappe.db.get_value("Company", company, "default_currency") company_currency = frappe.db.get_value("Company", company, "default_currency")

View File

@ -587,7 +587,11 @@ def validate_bom_no(item, bom_no):
frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item)) frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item))
@frappe.whitelist() @frappe.whitelist()
def get_children(): def get_children(doctype, parent=None, is_tree=False):
if not parent:
frappe.msgprint(_('Please select a BOM'))
return
if frappe.form_dict.parent: if frappe.form_dict.parent:
return frappe.db.sql("""select return frappe.db.sql("""select
bom_item.item_code, bom_item.item_code,

View File

@ -11,7 +11,7 @@ frappe.treeview_settings["BOM"] = {
title: "BOM", title: "BOM",
breadcrumb: "Manufacturing", breadcrumb: "Manufacturing",
disable_add_node: true, disable_add_node: true,
root_label: "bom", //fieldname from filters root_label: "All Bill of Materials", //fieldname from filters
get_label: function(node) { get_label: function(node) {
if(node.data.qty) { if(node.data.qty) {
return node.data.qty + " x " + node.data.item_code; return node.data.qty + " x " + node.data.item_code;

View File

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

View File

@ -6,7 +6,7 @@ import frappe, json
from frappe.utils import getdate, date_diff, add_days, cstr from frappe.utils import getdate, date_diff, add_days, cstr
from frappe import _, throw from frappe import _, throw
from frappe.utils.nestedset import NestedSet, rebuild_tree from frappe.utils.nestedset import NestedSet
class CircularReferenceError(frappe.ValidationError): pass class CircularReferenceError(frappe.ValidationError): pass
@ -198,22 +198,28 @@ def set_tasks_as_overdue():
and `status` not in ('Closed', 'Cancelled')""") and `status` not in ('Closed', 'Cancelled')""")
@frappe.whitelist() @frappe.whitelist()
def get_children(): def get_children(doctype, parent, task=None, project=None, is_root=False):
doctype = frappe.local.form_dict.get('doctype') conditions = ''
parent_field = 'parent_' + doctype.lower().replace(' ', '_') if task:
parent = frappe.form_dict.get("parent") or "" # 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": if project:
parent = "" conditions += ' and project = "{0}"'.format(frappe.db.escape(project))
tasks = frappe.db.sql("""select name as value, tasks = frappe.db.sql("""select name as value,
subject as title,
is_group as expandable is_group as expandable
from `tab{doctype}` from `tabTask`
where docstatus < 2 where docstatus < 2
and ifnull(`{parent_field}`,'') = %s {conditions}
order by name""".format(doctype=frappe.db.escape(doctype), order by name""".format(conditions=conditions), as_dict=1)
parent_field=frappe.db.escape(parent_field)), (parent), as_dict=1)
# return tasks # return tasks
return tasks return tasks

View File

@ -4,6 +4,12 @@ frappe.treeview_settings['Task'] = {
get_tree_nodes: "erpnext.projects.doctype.task.task.get_children", get_tree_nodes: "erpnext.projects.doctype.task.task.get_children",
add_tree_node: "erpnext.projects.doctype.task.task.add_node", add_tree_node: "erpnext.projects.doctype.task.task.add_node",
filters: [ filters: [
{
fieldname: "project",
fieldtype:"Link",
options: "Project",
label: __("Project"),
},
{ {
fieldname: "task", fieldname: "task",
fieldtype:"Link", fieldtype:"Link",
@ -16,17 +22,12 @@ frappe.treeview_settings['Task'] = {
} }
} }
], ],
title: "Task",
breadcrumb: "Projects", breadcrumb: "Projects",
get_tree_root: false, get_tree_root: false,
root_label: "task", root_label: "All Tasks",
ignore_fields: ["parent_task"], ignore_fields: ["parent_task"],
get_label: function(node) {
return node.data.value;
},
onload: function(me) { onload: function(me) {
me.make_tree(); me.make_tree();
me.set_root = true;
}, },
toolbar: [ toolbar: [
{ {

View File

@ -139,25 +139,19 @@ class Warehouse(NestedSet):
return 1 return 1
@frappe.whitelist() @frappe.whitelist()
def get_children(): def get_children(doctype, parent=None, company=None, is_root=False):
from erpnext.stock.utils import get_stock_value_on from erpnext.stock.utils import get_stock_value_on
doctype = frappe.local.form_dict.get('doctype')
company = frappe.local.form_dict.get('company')
parent_field = 'parent_' + doctype.lower().replace(' ', '_') if is_root:
parent = frappe.form_dict.get("parent") or ""
if parent == "Warehouses":
parent = "" parent = ""
warehouses = frappe.db.sql("""select name as value, warehouses = frappe.db.sql("""select name as value,
is_group as expandable is_group as expandable
from `tab{doctype}` from `tabWarehouse`
where docstatus < 2 where docstatus < 2
and ifnull(`{parent_field}`,'') = %s and ifnull(`parent_warehouse`,'') = %s
and (`company` = %s or company is null or company = '') and (`company` = %s or company is null or company = '')
order by name""".format(doctype=frappe.db.escape(doctype), order by name""", (parent, company), as_dict=1)
parent_field=frappe.db.escape(parent_field)), (parent, company), as_dict=1)
# return warehouses # return warehouses
for wh in warehouses: for wh in warehouses: