[fix] treeview for tasks (#11515)
[fix] treeview for tasks
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 50530f5..0003990 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -630,7 +630,7 @@
'invoice_amount': flt(d.invoice_amount),
'payment_amount': flt(d.payment_amount),
'outstanding_amount': flt(d.invoice_amount - d.payment_amount, precision),
- 'due_date': frappe.db.get_value(d.voucher_type, d.voucher_no,
+ 'due_date': frappe.db.get_value(d.voucher_type, d.voucher_no,
"posting_date" if party_type=="Employee" else "due_date"),
}))
@@ -656,16 +656,14 @@
order_by="name")]
@frappe.whitelist()
-def get_children():
+def get_children(doctype, parent, company, is_root=False):
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(' ','_'))
doctype = frappe.db.escape(doctype)
# root
- if args['parent'] in ("Accounts", "Cost Centers"):
+ if is_root:
fields = ", root_type, report_type, account_currency" if doctype=="Account" else ""
acc = frappe.db.sql(""" select
name as value, is_group as expandable {fields}
@@ -675,7 +673,7 @@
order by name""".format(fields=fields, fieldname = fieldname, doctype=doctype),
company, as_dict=1)
- if args["parent"]=="Accounts":
+ if parent=="Accounts":
sort_root_accounts(acc)
else:
# other
@@ -686,7 +684,7 @@
where ifnull(`parent_{fieldname}`,'') = %s
and docstatus<2
order by name""".format(fields=fields, fieldname=fieldname, doctype=doctype),
- args['parent'], as_dict=1)
+ parent, as_dict=1)
if doctype == 'Account':
company_currency = frappe.db.get_value("Company", company, "default_currency")
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index b140bf5..d0cf609 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -587,7 +587,11 @@
frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item))
@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:
return frappe.db.sql("""select
bom_item.item_code,
diff --git a/erpnext/manufacturing/doctype/bom/bom_tree.js b/erpnext/manufacturing/doctype/bom/bom_tree.js
index 09fe037..854f633 100644
--- a/erpnext/manufacturing/doctype/bom/bom_tree.js
+++ b/erpnext/manufacturing/doctype/bom/bom_tree.js
@@ -11,7 +11,7 @@
title: "BOM",
breadcrumb: "Manufacturing",
disable_add_node: true,
- root_label: "bom", //fieldname from filters
+ root_label: "All Bill of Materials", //fieldname from filters
get_label: function(node) {
if(node.data.qty) {
return node.data.qty + " x " + node.data.item_code;
diff --git a/erpnext/projects/doctype/task/task.json b/erpnext/projects/doctype/task/task.json
index 41950a3..8e72d03 100644
--- a/erpnext/projects/doctype/task/task.json
+++ b/erpnext/projects/doctype/task/task.json
@@ -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",
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index 5b1bcaf..fa56a95 100644
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -6,7 +6,7 @@
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 @@
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 @@
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
diff --git a/erpnext/projects/doctype/task/task_tree.js b/erpnext/projects/doctype/task/task_tree.js
index f11c34f..935a1e0 100644
--- a/erpnext/projects/doctype/task/task_tree.js
+++ b/erpnext/projects/doctype/task/task_tree.js
@@ -5,28 +5,29 @@
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 @@
'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",
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index 4f7cf0b..058828c 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -90,10 +90,10 @@
def get_new_warehouse_name_without_abbr(self, name):
company_abbr = frappe.db.get_value("Company", self.company, "abbr")
parts = name.rsplit(" - ", 1)
-
+
if parts[-1].lower() == company_abbr.lower():
name = parts[0]
-
+
return name
def recalculate_bin_qty(self, new_name):
@@ -139,25 +139,19 @@
return 1
@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
- doctype = frappe.local.form_dict.get('doctype')
- company = frappe.local.form_dict.get('company')
- parent_field = 'parent_' + doctype.lower().replace(' ', '_')
- parent = frappe.form_dict.get("parent") or ""
-
- if parent == "Warehouses":
+ if is_root:
parent = ""
warehouses = frappe.db.sql("""select name as value,
is_group as expandable
- from `tab{doctype}`
+ from `tabWarehouse`
where docstatus < 2
- and ifnull(`{parent_field}`,'') = %s
+ and ifnull(`parent_warehouse`,'') = %s
and (`company` = %s or company is null or company = '')
- order by name""".format(doctype=frappe.db.escape(doctype),
- parent_field=frappe.db.escape(parent_field)), (parent, company), as_dict=1)
+ order by name""", (parent, company), as_dict=1)
# return warehouses
for wh in warehouses: