[fix] deprecate browser pages for accounts, cost_center, sales , bom, item group

This commit is contained in:
Saurabh 2016-06-21 12:33:12 +05:30
parent 9c7b0079c5
commit a9ba7343c4
19 changed files with 64 additions and 787 deletions

View File

@ -10,7 +10,7 @@ frappe.treeview_settings["Account"] = {
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
}],
root_label: "Accounts",
get_tree_nodes: 'erpnext.accounts.page.accounts_browser.accounts_browser.get_children',
get_tree_nodes: 'erpnext.accounts.utils.get_children',
add_tree_node: 'erpnext.accounts.utils.add_ac',
menu_items:[
{

View File

@ -9,7 +9,7 @@ frappe.treeview_settings["Cost Center"] = {
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
}],
root_label: "Cost Centers",
get_tree_nodes: 'erpnext.accounts.page.accounts_browser.accounts_browser.get_children',
get_tree_nodes: 'erpnext.accounts.utils.get_children',
add_tree_node: 'erpnext.accounts.utils.add_cc',
menu_items:[
{

View File

@ -1 +0,0 @@
Tree view browser for Chart of Accounts and Chart of Cost Centers

View File

@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@ -1,334 +0,0 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
// tree of chart of accounts / cost centers
// multiple companies
// add node
// edit node
// see ledger
frappe.pages["Accounts Browser"].on_page_load = function(wrapper){
frappe.ui.make_app_page({
parent: wrapper,
single_column: true
})
frappe.breadcrumbs.add("Accounts");
var main = wrapper.page.main,
chart_area = $("<div>")
.css({"margin-bottom": "15px", "min-height": "200px"})
.appendTo(main),
help_area = $('<hr><div style="padding: 0px 15px;">'+
'<h4>'+__('Quick Help')+'</h4>'+
'<ol>'+
'<li>'+__('To add child nodes, explore tree and click on the node under which you want to add more nodes.')+'</li>'+
'<li>'+
__('Accounting Entries can be made against leaf nodes. Entries against Groups are not allowed.')+
'</li>'+
'<li>'+__('Please do NOT create Accounts for Customers and Suppliers. They are created directly from the Customer / Supplier masters.')+'</li>'+
'<li>'+
'<b>'+__('To create a Bank Account')+'</b>: '+
__('Go to the appropriate group (usually Application of Funds > Current Assets > Bank Accounts and create a new Account (by clicking on Add Child) of type "Bank"')+
'</li>'+
'<li>'+
'<b>'+__('To create a Tax Account') +'</b>: '+
__('Go to the appropriate group (usually Source of Funds > Current Liabilities > Taxes and Duties and create a new Account (by clicking on Add Child) of type "Tax" and do mention the Tax rate.')+
'</li>'+
'</ol>'+
'<p>'+__('Please setup your chart of accounts before you start Accounting Entries')+'</p></div>').appendTo(main);
if (frappe.boot.user.can_create.indexOf("Company") !== -1) {
wrapper.page.add_menu_item(__('New Company'), function() { newdoc('Company'); }, true);
}
wrapper.page.add_menu_item(__('Refresh'), function() {
wrapper.$company_select.change();
});
wrapper.page.set_primary_action(__('New'), function() {
erpnext.account_chart && erpnext.account_chart.make_new();
}, "octicon octicon-plus");
var company_list = $.map(locals[':Company'], function(c) { return c.name; }).sort();
// company-select
wrapper.$company_select = wrapper.page.add_select("Company", company_list)
.change(function() {
var ctype = frappe.get_route()[1] || 'Account';
erpnext.account_chart = new erpnext.AccountsChart(ctype, $(this).val(),
chart_area.get(0), wrapper.page);
})
if(frappe.defaults.get_default('company')) {
wrapper.$company_select.val(frappe.defaults.get_default('company'));
}
wrapper.$company_select.change();
}
frappe.pages["Accounts Browser"].on_page_show = function(wrapper){
// set route
var ctype = frappe.get_route()[1] || 'Account';
if(frappe.route_options) {
if(frappe.route_options.company) {
wrapper.$company_select.val(frappe.route_options.company).change();
}
frappe.route_options = null;
} else if(erpnext.account_chart && erpnext.account_chart.ctype != ctype) {
wrapper.$company_select.change();
}
}
erpnext.AccountsChart = Class.extend({
init: function(ctype, company, wrapper, page) {
$(wrapper).empty();
var me = this;
me.ctype = ctype;
me.can_create = frappe.model.can_create(this.ctype);
me.can_delete = frappe.model.can_delete(this.ctype);
me.can_write = frappe.model.can_write(this.ctype);
me.page = page;
me.set_title();
// __("Accounts"), __("Cost Centers")
me.company = company;
this.tree = new frappe.ui.Tree({
parent: $(wrapper),
label: ctype==="Account" ? "Accounts" : "Cost Centers",
args: {ctype: ctype, comp: company},
method: 'erpnext.accounts.page.accounts_browser.accounts_browser.get_children',
click: function(link) {
// bold
$('.bold').removeClass('bold'); // deselect
$(link).parent().find('.balance-area:first').addClass('bold'); // select
},
toolbar: [
{ toggle_btn: true },
{
label: __("Open"),
condition: function(node) { return !node.root },
click: function(node, btn) {
frappe.set_route("Form", me.ctype, node.label);
}
},
{
condition: function(node) { return node.expandable; },
label: __("Add Child"),
click: function() {
me.make_new()
},
btnClass: "hidden-xs"
},
{
condition: function(node) {
return !node.root && me.ctype === 'Account'
&& frappe.boot.user.can_read.indexOf("GL Entry") !== -1
},
label: __("View Ledger"),
click: function(node, btn) {
frappe.route_options = {
"account": node.label,
"from_date": sys_defaults.year_start_date,
"to_date": sys_defaults.year_end_date,
"company": me.company
};
frappe.set_route("query-report", "General Ledger");
},
btnClass: "hidden-xs"
},
{
condition: function(node) { return !node.root && me.can_write },
label: __("Rename"),
click: function(node) {
frappe.model.rename_doc(me.ctype, node.label, function(new_name) {
node.reload_parent();
});
},
btnClass: "hidden-xs"
},
{
condition: function(node) { return !node.root && me.can_delete },
label: __("Delete"),
click: function(node) {
frappe.model.delete_doc(me.ctype, node.label, function() {
node.parent.remove();
});
},
btnClass: "hidden-xs"
}
],
onrender: function(node) {
var dr_or_cr = node.data.balance < 0 ? "Cr" : "Dr";
if (me.ctype == 'Account' && node.data && node.data.balance!==undefined) {
$('<span class="balance-area pull-right text-muted small">'
+ (node.data.balance_in_account_currency ?
(format_currency(Math.abs(node.data.balance_in_account_currency),
node.data.account_currency) + " / ") : "")
+ format_currency(Math.abs(node.data.balance), node.data.company_currency)
+ " " + dr_or_cr
+ '</span>').insertBefore(node.$ul);
}
}
});
},
set_title: function(val) {
var chart_str = this.ctype=="Account" ? __("Chart of Accounts") : __("Chart of Cost Centers");
if(val) {
this.page.set_title(chart_str + " - " + cstr(val));
} else {
this.page.set_title(chart_str);
}
},
make_new: function() {
if(this.ctype=='Account') {
this.new_account();
} else {
this.new_cost_center();
}
},
new_account: function() {
var me = this;
var node = me.tree.get_selected_node();
if(!(node && node.expandable)) {
frappe.msgprint(__("Select a group node first."));
return;
}
// the dialog
var d = new frappe.ui.Dialog({
title:__('New Account'),
fields: [
{fieldtype:'Data', fieldname:'account_name', label:__('New Account Name'), reqd:true,
description: __("Name of new Account. Note: Please don't create accounts for Customers and Suppliers")},
{fieldtype:'Check', fieldname:'is_group', label:__('Is Group'),
description: __('Further accounts can be made under Groups, but entries can be made against non-Groups')},
{fieldtype:'Select', fieldname:'root_type', label:__('Root Type'),
options: ['Asset', 'Liability', 'Equity', 'Income', 'Expense'].join('\n'),
},
{fieldtype:'Select', fieldname:'account_type', label:__('Account Type'),
options: ['', 'Bank', 'Cash', 'Warehouse', 'Tax', 'Chargeable'].join('\n'),
description: __("Optional. This setting will be used to filter in various transactions.") },
{fieldtype:'Float', fieldname:'tax_rate', label:__('Tax Rate')},
{fieldtype:'Link', fieldname:'warehouse', label:__('Warehouse'), options:"Warehouse"},
{fieldtype:'Link', fieldname:'account_currency', label:__('Currency'), options:"Currency",
description: __("Optional. Sets company's default currency, if not specified.")}
]
})
var fd = d.fields_dict;
// account type if ledger
$(fd.is_group.input).change(function() {
if($(this).prop("checked")) {
$(fd.account_type.wrapper).toggle(false);
$(fd.tax_rate.wrapper).toggle(false);
$(fd.warehouse.wrapper).toggle(false);
} else {
$(fd.account_type.wrapper).toggle(node.root ? false : true);
fd.account_type.$input.trigger("change");
}
});
// tax rate if tax
$(fd.account_type.input).change(function() {
$(fd.tax_rate.wrapper).toggle(fd.account_type.get_value()==='Tax');
$(fd.warehouse.wrapper).toggle(fd.account_type.get_value()==='Warehouse');
})
// create
d.set_primary_action(__("Create New"), function() {
var btn = this;
var v = d.get_values();
if(!v) return;
if(v.account_type==="Warehouse" && !v.warehouse) {
msgprint(__("Warehouse is required"));
return;
}
var node = me.tree.get_selected_node();
v.parent_account = node.label;
v.company = me.company;
if(node.root) {
v.is_root = 1;
v.parent_account = null;
} else {
v.is_root = 0;
v.root_type = null;
}
return frappe.call({
args: v,
method: 'erpnext.accounts.utils.add_ac',
callback: function(r) {
d.hide();
if(node.expanded) {
node.toggle_node();
}
node.load();
}
});
});
// show
d.on_page_show = function() {
$(fd.is_group.input).change();
$(fd.account_type.input).change();
}
$(fd.is_group.input).prop("checked", false).change();
// In case of root, show root type and hide account_type, is_group
$(fd.root_type.wrapper).toggle(node.root);
$(fd.is_group.wrapper).toggle(!node.root);
d.show();
},
new_cost_center: function(){
var me = this;
// the dialog
var d = new frappe.ui.Dialog({
title:__('New Cost Center'),
fields: [
{fieldtype:'Data', fieldname:'cost_center_name', label:__('New Cost Center Name'), reqd:true},
{fieldtype:'Check', fieldname:'is_group', label:__('Is Group'),
description:__('Further cost centers can be made under Groups but entries can be made against non-Groups')},
{fieldtype:'Button', fieldname:'create_new', label:__('Create New') }
]
});
// create
$(d.fields_dict.create_new.input).click(function() {
var v = d.get_values();
if(!v) return;
var node = me.tree.get_selected_node();
v.parent_cost_center = node.label;
v.company = me.company;
return frappe.call({
args: v,
method: 'erpnext.accounts.utils.add_cc',
callback: function(r) {
d.hide();
if(node.expanded) {
node.toggle_node();
}
node.load();
}
});
});
d.show();
}
});

View File

@ -1,22 +0,0 @@
{
"creation": "2012-06-14 15:07:28.000000",
"docstatus": 0,
"doctype": "Page",
"icon": "icon-sitemap",
"idx": 1,
"modified": "2013-07-11 14:39:42.000000",
"modified_by": "Administrator",
"module": "Accounts",
"name": "accounts-browser",
"owner": "Administrator",
"page_name": "Accounts Browser",
"roles": [
{
"role": "Accounts User"
},
{
"role": "Accounts Manager"
}
],
"standard": "Yes"
}

View File

@ -1,57 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import frappe.defaults
from frappe.utils import flt
from erpnext.accounts.utils import get_balance_on
from erpnext.accounts.report.financial_statements import sort_root_accounts
@frappe.whitelist()
def get_companies():
"""get a list of companies based on permission"""
return [d.name for d in frappe.get_list("Company", fields=["name"],
order_by="name")]
@frappe.whitelist()
def get_children():
args = frappe.local.form_dict
ctype, company = args['ctype'], args['comp']
fieldname = frappe.db.escape(ctype.lower().replace(' ','_'))
doctype = frappe.db.escape(ctype)
# root
if args['parent'] in ("Accounts", "Cost Centers"):
fields = ", root_type, report_type, account_currency" if ctype=="Account" else ""
acc = frappe.db.sql(""" select
name as value, is_group as expandable {fields}
from `tab{doctype}`
where ifnull(`parent_{fieldname}`,'') = ''
and `company` = %s and docstatus<2
order by name""".format(fields=fields, fieldname = fieldname, doctype=doctype),
company, as_dict=1)
if args["parent"]=="Accounts":
sort_root_accounts(acc)
else:
# other
fields = ", account_currency" if ctype=="Account" else ""
acc = frappe.db.sql("""select
name as value, is_group as expandable, parent_{fieldname} as parent {fields}
from `tab{doctype}`
where ifnull(`parent_{fieldname}`,'') = %s
and docstatus<2
order by name""".format(fields=fields, fieldname=fieldname, doctype=doctype),
args['parent'], as_dict=1)
if ctype == 'Account':
company_currency = frappe.db.get_value("Company", company, "default_currency")
for each in acc:
each["company_currency"] = company_currency
each["balance"] = flt(get_balance_on(each.get("value"), in_account_currency=False))
if each.account_currency != company_currency:
each["balance_in_account_currency"] = flt(get_balance_on(each.get("value")))
return acc

View File

@ -9,7 +9,8 @@ from frappe import throw, _
from frappe.utils import formatdate
# imported to enable erpnext.accounts.utils.get_account_currency
from erpnext.accounts.doctype.account.account import get_account_currency
import frappe.defaults
from erpnext.accounts.report.financial_statements import sort_root_accounts
class FiscalYearError(frappe.ValidationError): pass
@ -436,3 +437,51 @@ def get_account_name(account_type=None, root_type=None, is_group=None, account_c
"account_currency": account_currency or frappe.defaults.get_defaults().currency,
"company": company or frappe.defaults.get_defaults().company
}, "name")
@frappe.whitelist()
def get_companies():
"""get a list of companies based on permission"""
return [d.name for d in frappe.get_list("Company", fields=["name"],
order_by="name")]
@frappe.whitelist()
def get_children():
args = frappe.local.form_dict
ctype, company = args['ctype'], args['comp']
fieldname = frappe.db.escape(ctype.lower().replace(' ','_'))
doctype = frappe.db.escape(ctype)
# root
if args['parent'] in ("Accounts", "Cost Centers"):
fields = ", root_type, report_type, account_currency" if ctype=="Account" else ""
acc = frappe.db.sql(""" select
name as value, is_group as expandable {fields}
from `tab{doctype}`
where ifnull(`parent_{fieldname}`,'') = ''
and `company` = %s and docstatus<2
order by name""".format(fields=fields, fieldname = fieldname, doctype=doctype),
company, as_dict=1)
if args["parent"]=="Accounts":
sort_root_accounts(acc)
else:
# other
fields = ", account_currency" if ctype=="Account" else ""
acc = frappe.db.sql("""select
name as value, is_group as expandable, parent_{fieldname} as parent {fields}
from `tab{doctype}`
where ifnull(`parent_{fieldname}`,'') = %s
and docstatus<2
order by name""".format(fields=fields, fieldname=fieldname, doctype=doctype),
args['parent'], as_dict=1)
if ctype == 'Account':
company_currency = frappe.db.get_value("Company", company, "default_currency")
for each in acc:
each["company_currency"] = company_currency
each["balance"] = flt(get_balance_on(each.get("value"), in_account_currency=False))
if each.account_currency != company_currency:
each["balance_in_account_currency"] = flt(get_balance_on(each.get("value")))
return acc

View File

@ -438,3 +438,14 @@ def validate_bom_no(item, bom_no):
if item and not (bom.item.lower() == item.lower() or \
bom.item.lower() == cstr(frappe.db.get_value("Item", item, "variant_of")).lower()):
frappe.throw(_("BOM {0} does not belong to Item {1}").format(bom_no, item))
@frappe.whitelist()
def get_children(parent=None):
if parent:
return frappe.db.sql("""select item_code,
bom_no as value, qty,
if(ifnull(bom_no, "")!="", 1, 0) as expandable
from `tabBOM Item`
where parent=%s
order by idx
""", parent, as_dict=True)

View File

@ -1,5 +1,5 @@
frappe.treeview_settings["BOM"] = {
get_tree_nodes: 'erpnext.manufacturing.page.bom_browser.bom_browser.get_children',
get_tree_nodes: 'erpnext.manufacturing.doctype.bom.bom.get_children',
filters: [
{
fieldname: "bom",

View File

@ -1,89 +0,0 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
frappe.pages['bom-browser'].on_page_load = function(wrapper) {
var page = frappe.ui.make_app_page({
parent: wrapper,
title: 'BOM Browser',
single_column: true
});
page.main.css({
"min-height": "300px",
"padding-bottom": "25px"
});
page.tree_area = $('<div class="padding"><p class="text-muted">'+
__("Select BOM to start")
+'</p></div>').appendTo(page.main);
frappe.breadcrumbs.add(frappe.breadcrumbs.last_module || "Manufacturing");
var make_tree = function() {
erpnext.bom_tree = new erpnext.BOMTree(page.$bom_select.val(), page, page.tree_area);
}
page.$bom_select = wrapper.page.add_field({fieldname: "bom",
fieldtype:"Link", options: "BOM", label: __("BOM")}).$input
.change(function() {
make_tree();
});
page.set_secondary_action(__('Refresh'), function() {
make_tree();
});
}
frappe.pages['bom-browser'].on_page_show = function(wrapper){
// set from route
var bom = null;
if(frappe.get_route()[1]) {
var bom = frappe.get_route().splice(1).join("/");
}
if(frappe.route_options && frappe.route_options.bom) {
var bom = frappe.route_options.bom;
}
if(bom) {
wrapper.page.$bom_select.val(bom).trigger("change");
}
};
erpnext.BOMTree = Class.extend({
init: function(root, page, parent) {
$(parent).empty();
var me = this;
me.page = page;
me.bom = page.$bom_select.val();
me.can_read = frappe.model.can_read("BOM");
me.can_create = frappe.boot.user.can_create.indexOf("BOM") !== -1 ||
frappe.boot.user.in_create.indexOf("BOM") !== -1;
me.can_write = frappe.model.can_write("BOM");
me.can_delete = frappe.model.can_delete("BOM");
this.tree = new frappe.ui.Tree({
parent: $(parent),
label: me.bom,
args: {parent: me.bom},
method: 'erpnext.manufacturing.page.bom_browser.bom_browser.get_children',
toolbar: [
{toggle_btn: true},
{
label:__("Edit"),
condition: function(node) {
return node.expandable;
},
click: function(node) {
frappe.set_route("Form", "BOM", node.data.value);
}
}
],
get_label: function(node) {
if(node.data.qty) {
return node.data.qty + " x " + node.data.item_code;
} else {
return node.data.item_code || node.data.value;
}
}
});
}
});

View File

@ -1,21 +0,0 @@
{
"content": null,
"creation": "2015-05-25 02:57:33.472044",
"docstatus": 0,
"doctype": "Page",
"modified": "2015-05-25 02:57:33.472044",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "bom-browser",
"owner": "Administrator",
"page_name": "bom-browser",
"roles": [
{
"role": "Manufacturing User"
}
],
"script": null,
"standard": "Yes",
"style": null,
"title": "BOM Browser"
}

View File

@ -1,16 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
@frappe.whitelist()
def get_children():
parent = frappe.local.form_dict.get('bom')
return frappe.db.sql("""select item_code,
bom_no as value, qty,
if(ifnull(bom_no, "")!="", 1, 0) as expandable
from `tabBOM Item`
where parent=%s
order by idx
""", parent, as_dict=True)

View File

@ -1 +0,0 @@
Tree editor for Territory, Customer Group, Item Group, Sales Partner

View File

@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@ -1,37 +0,0 @@
{
"creation": "2012-06-14 15:07:26.000000",
"docstatus": 0,
"doctype": "Page",
"icon": "icon-sitemap",
"idx": 1,
"modified": "2013-07-11 14:43:56.000000",
"modified_by": "Administrator",
"module": "Selling",
"name": "sales-browser",
"owner": "Administrator",
"page_name": "Sales Browser",
"roles": [
{
"role": "Sales Master Manager"
},
{
"role": "Material Master Manager"
},
{
"role": "Accounts Manager"
},
{
"role": "Sales Master Manager"
},
{
"role": "Purchase Manager"
},
{
"role": "Purchase Master Manager"
},
{
"role": "Material Manager"
}
],
"standard": "Yes"
}

View File

@ -1,37 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
@frappe.whitelist()
def get_children():
ctype = frappe.local.form_dict.get('ctype')
parent_field = 'parent_' + ctype.lower().replace(' ', '_')
parent = frappe.form_dict.get("parent") or ""
return frappe.db.sql("""select name as value,
if(is_group='Yes', 1, 0) as expandable
from `tab{ctype}`
where docstatus < 2
and ifnull(`{parent_field}`,'') = %s
order by name""".format(ctype=frappe.db.escape(ctype), parent_field=frappe.db.escape(parent_field)),
parent, as_dict=1)
@frappe.whitelist()
def add_node():
ctype = frappe.form_dict.get('ctype')
parent_field = 'parent_' + ctype.lower().replace(' ', '_')
name_field = ctype.lower().replace(' ', '_') + '_name'
doc = frappe.new_doc(ctype)
doc.update({
name_field: frappe.form_dict['name_field'],
parent_field: frappe.form_dict['parent'],
"is_group": frappe.form_dict['is_group']
})
if ctype == "Sales Person":
doc.employee = frappe.form_dict.get('employee')
doc.save()

View File

@ -1,166 +0,0 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
frappe.pages["Sales Browser"].on_page_load = function(wrapper){
var page = frappe.ui.make_app_page({
parent: wrapper,
single_column: true,
});
wrapper.page.add_menu_item(__('Refresh'), function() {
wrapper.make_tree();
});
wrapper.make_tree = function() {
var ctype = frappe.get_route()[1] || 'Territory';
return frappe.call({
method: 'erpnext.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, page,
page.main.css({
"min-height": "300px",
"padding-bottom": "25px"
}));
}
});
}
wrapper.make_tree();
}
frappe.pages['Sales Browser'].on_page_show = function(wrapper){
// set route
var ctype = frappe.get_route()[1] || 'Territory';
wrapper.page.set_title(__('{0} Tree',[__(ctype)]));
if(erpnext.sales_chart && erpnext.sales_chart.ctype != ctype) {
wrapper.make_tree();
}
frappe.breadcrumbs.add(frappe.breadcrumbs.last_module || "Selling");
};
erpnext.SalesChart = Class.extend({
init: function(ctype, root, page, parent) {
$(parent).empty();
var me = this;
me.ctype = ctype;
me.page = page;
me.can_read = frappe.model.can_read(this.ctype);
me.can_create = frappe.boot.user.can_create.indexOf(this.ctype) !== -1 ||
frappe.boot.user.in_create.indexOf(this.ctype) !== -1;
me.can_write = frappe.model.can_write(this.ctype);
me.can_delete = frappe.model.can_delete(this.ctype);
me.page.set_primary_action(__("New"), function() {
me.new_node();
}, "octicon octicon-plus");
this.tree = new frappe.ui.Tree({
parent: $(parent),
label: __(root),
args: {ctype: ctype},
method: 'erpnext.selling.page.sales_browser.sales_browser.get_children',
toolbar: [
{toggle_btn: true},
{
label:__("Edit"),
condition: function(node) {
return !node.root && me.can_read;
},
click: function(node) {
frappe.set_route("Form", me.ctype, node.label);
}
},
{
label:__("Add Child"),
condition: function(node) { return me.can_create && node.expandable; },
click: function(node) {
me.new_node();
},
btnClass: "hidden-xs"
},
{
label:__("Rename"),
condition: function(node) { return !node.root && me.can_write; },
click: function(node) {
frappe.model.rename_doc(me.ctype, node.label, function(new_name) {
node.$a.html(new_name);
});
},
btnClass: "hidden-xs"
},
{
label:__("Delete"),
condition: function(node) { return !node.root && me.can_delete; },
click: function(node) {
frappe.model.delete_doc(me.ctype, node.label, function() {
node.parent.remove();
});
},
btnClass: "hidden-xs"
}
]
});
},
new_node: function() {
var me = this;
var node = me.tree.get_selected_node();
if(!(node && node.expandable)) {
frappe.msgprint(__("Select a group node first."));
return;
}
var fields = [
{fieldtype:'Data', fieldname: 'name_field',
label:__('New {0} Name',[__(me.ctype)]), reqd:true},
{fieldtype:'Select', fieldname:'is_group', label:__('Group Node'), options:'No\nYes',
description: __("Further nodes can be only created under 'Group' type nodes")}
]
if(me.ctype == "Sales Person") {
fields.splice(-1, 0, {fieldtype:'Link', fieldname:'employee', label:__('Employee'),
options:'Employee', description: __("Please enter Employee Id of this sales person")});
}
// the dialog
var d = new frappe.ui.Dialog({
title: __('New {0}',[__(me.ctype)]),
fields: fields
})
d.set_value("is_group", "No");
// create
d.set_primary_action(__("Create New"), function() {
var btn = this;
var v = d.get_values();
if(!v) return;
var node = me.tree.get_selected_node();
v.parent = node.label;
v.ctype = me.ctype;
return frappe.call({
method: 'erpnext.selling.page.sales_browser.sales_browser.add_node',
args: v,
callback: function(r) {
if(!r.exc) {
d.hide();
if(node.expanded) {
node.toggle_node();
}
node.reload();
}
}
});
});
d.show();
},
});