dynamic query for root in sales browser, validation for tree structure document

This commit is contained in:
Nabin Hait
2012-12-12 16:26:39 +05:30
parent 73ccac4ccb
commit 06cbd3427f
11 changed files with 59 additions and 33 deletions

View File

@@ -24,7 +24,14 @@ pscript['onload_Sales Browser'] = function(wrapper){
wrapper.make_tree = function() {
var ctype = wn.get_route()[1] || 'Territory';
erpnext.sales_chart = new erpnext.SalesChart(ctype, wrapper);
wn.call({
method: 'selling.page.sales_browser.sales_browser.get_children',
args: {ctype: ctype},
callback: function(r) {
var root = r.message[0]["value"];
erpnext.sales_chart = new erpnext.SalesChart(ctype, root, wrapper);
}
});
}
wrapper.make_tree();
@@ -42,20 +49,13 @@ pscript['onshow_Sales Browser'] = function(wrapper){
};
erpnext.SalesChart = Class.extend({
init: function(ctype, wrapper) {
var root_nodes = {
'Territory': 'All Territories',
'Item Group': 'All Item Groups',
'Customer Group': 'All Customer Groups',
'Sales Person': 'All Sales Persons'
}
init: function(ctype, root, wrapper) {
$(wrapper).find('.tree-area').empty();
var me = this;
me.ctype = ctype;
this.tree = new wn.ui.Tree({
parent: $(wrapper).find('.tree-area'),
label: root_nodes[ctype],
label: root,
args: {ctype: ctype},
method: 'selling.page.sales_browser.sales_browser.get_children',
click: function(link) {
@@ -72,7 +72,7 @@ erpnext.SalesChart = Class.extend({
}
});
this.tree.rootnode.$a
.data('node-data', {value: root_nodes[ctype], expandable:1})
.data('node-data', {value: root, expandable:1})
.click();
},
make_link_toolbar: function(link) {

View File

@@ -1,11 +1,14 @@
from __future__ import unicode_literals
import webnotes
@webnotes.whitelist()
def get_children():
ctype = webnotes.form_dict.get('ctype')
webnotes.form_dict['parent_field'] = 'parent_' + ctype.lower().replace(' ', '_')
if not webnotes.form_dict.get('parent'):
webnotes.form_dict['parent'] = ''
return webnotes.conn.sql("""select name as value,
if(is_group='Yes', 1, 0) as expandable
from `tab%(ctype)s`