Customer Group and Territory JS errors

It is not possible to select or create Customer Group or Territory, page is empty.

JS console:
Request:
http://127.0.0.1:8000/?doctype=Customer+Group&with_parent=1&cmd=frappe.desk.form.load.getdoctype&_=1451460241275

Result:

{"user_permissions":{},"docs":[{"istable":0,"__linked_with":null,"in_create":0,"__print_formats":[],"__calendar_js":null,"allow_import":1,"creation":"2013-01-10 16:34:23","search_fields":"parent_customer_group","module":"Setup","autoname":"field:customer_group_name","__messages":null,"read_only_onload":0,"__map_js":null,"modified":"2015-11-16 06:29:44.374615","owner":"Administrator","in_dialog":0,"document_type":"Setup","__form_grid_templates":null,"icon":"icon-sitemap","read_only":0,"__listview_template":null,"__css":null,"hide_heading":0,"modified_by":"Administrator","name":"Customer Group","idx":1,"allow_rename":1,"issingle":0,"__workflow_docs":[],"doctype":"DocType","custom":0,"is_submittable":0,"max_attachments":0,"__js":"\n\n// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors\n// License: GNU General Public License v3. See license.txt\n\ncur_frm.list_route = \"Sales Browser/Customer Group\";\n\ncur_frm.cscript.refresh = function(doc, cdt, cdn) {\n\tcur_frm.cscript.set_root_readonly(doc);\n}\n\ncur_frm.cscript.set_root_readonly = function(doc) {\n\t// read-only for root customer group\n\tif(!doc.parent_customer_group) {\n\t\tcur_frm.set_read_only();\n\t\tcur_frm.set_intro(__(\"This is a root customer group and cannot be edited.\"));\n\t} else {\n\t\tcur_frm.set_intro(null);\n\t}\n}\n\n//get query select Customer Group\ncur_frm.fields_dict['parent_customer_group'].get_query = function(doc,cdt,cdn) {\n\treturn {\n\t\tfilters: {\n\t\t\t'is_group': \"Yes\"\n\t\t}\n\t}\n}\n\ncur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) {\n\tvar d  = locals[cdt][cdn];\n\treturn {\n\t\tfilters: {\n\t\t\t'account_type': 'Receivable',\n\t\t\t'company': d.company,\n\t\t\t\"is_group\": 0\n\t\t}\n\t}\n}\n\n\n","fields":[{"collapsible":0,"no_copy":1,"oldfieldtype":"Data","creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","oldfieldname":"customer_group_name","reqd":1,"in_list_view":1,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Customer Group Name","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"bold":0,"parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"64ff65194c","idx":1,"doctype":"DocField","length":0,"fieldname":"customer_group_name","fieldtype":"Data","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"oldfieldtype":"Link","creation":"2013-01-10 16:34:23","search_fields":["parent_customer_group"],"modified":"2015-12-29 20:09:39.890316","oldfieldname":"parent_customer_group","reqd":0,"in_list_view":1,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":1,"parenttype":"DocType","label":"Parent Customer Group","print_hide_if_no_value":0,"linked_document_type":"Setup","set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"description":"","parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"bold":0,"unique":0,"name":"103b2660a6","idx":2,"doctype":"DocField","length":0,"fieldname":"parent_customer_group","fieldtype":"Link","options":"Customer Group","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"oldfieldtype":"Select","creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","oldfieldname":"is_group","reqd":1,"in_list_view":1,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Has Child Node","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"description":"Only leaf nodes are allowed in transaction","parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"bold":0,"unique":0,"name":"782fd9d7ec","idx":3,"doctype":"DocField","length":0,"fieldname":"is_group","fieldtype":"Select","options":"\nYes\nNo","report_hide":0,"parentfield":"fields"},{"allow_on_submit":0,"collapsible":0,"bold":0,"parent":"Customer Group","no_copy":0,"search_index":0,"creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","is_custom_field":null,"reqd":0,"in_list_view":0,"owner":"Administrator","unique":0,"in_filter":0,"read_only":0,"print_hide":0,"linked_document_type":null,"modified_by":"Administrator","name":"8200a45ab4","idx":4,"ignore_user_permissions":0,"doctype":"DocField","print_hide_if_no_value":0,"length":0,"fieldname":"cb0","fieldtype":"Column Break","set_only_once":0,"docstatus":0,"hidden":0,"parentfield":"fields","permlevel":0,"report_hide":0,"parenttype":"DocType"},{"collapsible":0,"no_copy":0,"creation":"2013-01-10 16:34:23","search_fields":["currency"],"modified":"2015-12-29 20:09:39.890316","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":1,"parenttype":"DocType","label":"Default Price List","print_hide_if_no_value":0,"linked_document_type":"Setup","set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"bold":0,"parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"9365a9c23a","idx":5,"doctype":"DocField","length":0,"fieldname":"default_price_list","fieldtype":"Link","options":"Price List","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Credit Days Based On","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"bold":0,"parent":"Customer Group","search_index":0,"allow_on_submit":0,"precision":"","is_custom_field":null,"unique":0,"name":"1f8ca80b52","idx":6,"doctype":"DocField","length":0,"fieldname":"credit_days_based_on","fieldtype":"Select","options":"\nFixed Days\nLast Day of the Next Month","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"depends_on":"eval:doc.credit_days_based_on=='Fixed Days'","creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Credit Days","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":0,"permlevel":1,"bold":0,"parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"8a5833bd41","idx":7,"doctype":"DocField","length":0,"fieldname":"credit_days","fieldtype":"Int","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Credit Limit","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":0,"permlevel":1,"bold":0,"parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"3c0cd70f4e","idx":8,"doctype":"DocField","length":0,"fieldname":"credit_limit","fieldtype":"Currency","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":1,"oldfieldtype":"Int","creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","oldfieldname":"lft","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":1,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"lft","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":1,"permlevel":0,"bold":0,"parent":"Customer Group","search_index":1,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"3af7d4728e","idx":9,"doctype":"DocField","length":0,"fieldname":"lft","fieldtype":"Int","report_hide":1,"parentfield":"fields"},{"collapsible":0,"no_copy":1,"oldfieldtype":"Int","creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","oldfieldname":"rgt","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":1,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"rgt","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":1,"permlevel":0,"bold":0,"parent":"Customer Group","search_index":1,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"e1acdc894a","idx":10,"doctype":"DocField","length":0,"fieldname":"rgt","fieldtype":"Int","report_hide":1,"parentfield":"fields"},{"collapsible":0,"no_copy":1,"oldfieldtype":"Data","creation":"2013-01-10 16:34:23","search_fields":["parent_customer_group"],"modified":"2015-12-29 20:09:39.890316","oldfieldname":"old_parent","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":1,"modified_by":"Administrator","ignore_user_permissions":1,"parenttype":"DocType","label":"old_parent","print_hide_if_no_value":0,"linked_document_type":"Setup","set_only_once":0,"docstatus":0,"hidden":1,"permlevel":0,"description":"","parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"bold":0,"unique":0,"name":"2c220f1716","idx":11,"doctype":"DocField","length":0,"fieldname":"old_parent","fieldtype":"Link","options":"Customer Group","report_hide":1,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Default Receivable Account","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"bold":0,"parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"87a5d7a517","idx":12,"doctype":"DocField","length":0,"fieldname":"default_receivable_account","fieldtype":"Section Break","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"depends_on":"eval:!doc.__islocal","creation":"2013-01-10 16:34:23","search_fields":null,"modified":"2015-12-29 20:09:39.890316","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Accounts","print_hide_if_no_value":0,"linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"description":"Mention if non-standard receivable account applicable","parent":"Customer Group","search_index":0,"allow_on_submit":0,"is_custom_field":null,"bold":0,"unique":0,"name":"ce86eb8e92","idx":13,"doctype":"DocField","length":0,"fieldname":"accounts","fieldtype":"Table","options":"Party Account","report_hide":0,"parentfield":"fields"}],"__list_js":null,"docstatus":0,"permissions":[{"parent":"Customer Group","read":1,"creation":"2013-01-10 16:34:23","share":0,"modified":"2015-12-29 20:09:39.890316","cancel":0,"if_owner":0,"export":0,"set_user_permissions":0,"owner":"Administrator","import":0,"apply_user_permissions":0,"delete":0,"modified_by":"Administrator","name":"eb86e23436","idx":1,"amend":0,"create":0,"doctype":"DocPerm","submit":0,"email":1,"write":0,"report":1,"role":"Sales Manager","print":1,"docstatus":0,"parentfield":"permissions","permlevel":0,"parenttype":"DocType"},{"parent":"Customer Group","read":1,"creation":"2013-01-10 16:34:23","share":0,"modified":"2015-12-29 20:09:39.890316","cancel":0,"if_owner":0,"export":0,"set_user_permissions":0,"owner":"Administrator","import":0,"apply_user_permissions":0,"delete":0,"modified_by":"Administrator","name":"f47befd154","idx":2,"amend":0,"create":0,"doctype":"DocPerm","submit":0,"email":1,"write":0,"report":1,"role":"Sales User","print":1,"docstatus":0,"parentfield":"permissions","permlevel":0,"parenttype":"DocType"},{"parent":"Customer Group","read":1,"creation":"2013-01-10 16:34:23","share":1,"modified":"2015-12-29 20:09:39.890316","cancel":0,"if_owner":0,"export":0,"set_user_permissions":0,"owner":"Administrator","import":0,"apply_user_permissions":0,"delete":1,"modified_by":"Administrator","name":"0f99107d5c","idx":3,"amend":0,"create":1,"doctype":"DocPerm","submit":0,"email":1,"write":1,"report":1,"role":"Sales Master Manager","print":1,"docstatus":0,"parentfield":"permissions","permlevel":0,"parenttype":"DocType"},{"parent":"Customer Group","read":1,"creation":"2013-01-10 16:34:23","share":0,"modified":"2015-12-29 20:09:39.890316","cancel":0,"if_owner":0,"export":0,"set_user_permissions":0,"owner":"Administrator","import":0,"apply_user_permissions":0,"delete":0,"modified_by":"Administrator","name":"900b41594f","idx":4,"amend":0,"create":0,"doctype":"DocPerm","submit":0,"email":0,"write":1,"report":0,"role":"Sales Master Manager","print":0,"docstatus":0,"parentfield":"permissions","permlevel":1,"parenttype":"DocType"},{"parent":"Customer Group","read":1,"creation":"2013-01-10 16:34:23","share":0,"modified":"2015-12-29 20:09:39.890316","cancel":0,"if_owner":0,"export":0,"set_user_permissions":0,"owner":"Administrator","import":0,"apply_user_permissions":0,"delete":0,"modified_by":"Administrator","name":"dc8ae22f8e","idx":5,"amend":0,"create":0,"doctype":"DocPerm","submit":0,"email":0,"write":0,"report":0,"role":"Sales User","print":0,"docstatus":0,"parentfield":"permissions","permlevel":1,"parenttype":"DocType"},{"parent":"Customer Group","read":1,"creation":"2013-01-10 16:34:23","share":0,"modified":"2015-12-29 20:09:39.890316","cancel":0,"if_owner":0,"export":0,"set_user_permissions":0,"owner":"Administrator","import":0,"apply_user_permissions":0,"delete":0,"modified_by":"Administrator","name":"3c4dd5f810","idx":6,"amend":0,"create":0,"doctype":"DocPerm","submit":0,"email":0,"write":0,"report":0,"role":"Sales Manager","print":0,"docstatus":0,"parentfield":"permissions","permlevel":1,"parenttype":"DocType"}],"hide_toolbar":0,"allow_copy":0},{"istable":1,"__linked_with":null,"in_create":0,"__print_formats":null,"__calendar_js":null,"allow_import":0,"creation":"2014-08-29 16:02:39.740505","__list_js":null,"module":"Accounts","modified":"2015-11-16 06:29:51.450360","__form_grid_templates":null,"sort_order":"DESC","__map_js":null,"__messages":null,"owner":"Administrator","in_dialog":0,"document_type":"","__js":null,"permissions":[],"read_only":0,"__listview_template":null,"__css":null,"hide_heading":0,"modified_by":"Administrator","name":"Party Account","idx":0,"allow_rename":0,"issingle":0,"__workflow_docs":null,"doctype":"DocType","custom":0,"is_submittable":0,"name_case":"","max_attachments":0,"read_only_onload":0,"fields":[{"collapsible":0,"no_copy":0,"creation":"2014-08-29 16:02:39.740505","search_fields":null,"modified":"2015-12-29 20:09:23.452904","reqd":1,"in_list_view":1,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Company","print_hide_if_no_value":0,"linked_document_type":"Setup","set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"bold":0,"parent":"Party Account","search_index":0,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"4fafec02e6","idx":1,"doctype":"DocField","length":0,"fieldname":"company","fieldtype":"Link","options":"Company","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"creation":"2014-08-29 16:02:39.740505","search_fields":null,"modified":"2015-12-29 20:09:23.452904","reqd":0,"in_list_view":0,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"","print_hide_if_no_value":0,"width":"50%","linked_document_type":null,"set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"bold":0,"parent":"Party Account","search_index":0,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"7d74c7d5cb","idx":2,"doctype":"DocField","length":0,"fieldname":"col_break1","fieldtype":"Column Break","report_hide":0,"parentfield":"fields"},{"collapsible":0,"no_copy":0,"creation":"2014-08-29 16:02:39.740505","search_fields":null,"modified":"2015-12-29 20:09:23.452904","reqd":1,"in_list_view":1,"owner":"Administrator","in_filter":0,"read_only":0,"print_hide":0,"modified_by":"Administrator","ignore_user_permissions":0,"parenttype":"DocType","label":"Account","print_hide_if_no_value":0,"linked_document_type":"Setup","set_only_once":0,"docstatus":0,"hidden":0,"permlevel":0,"bold":0,"parent":"Party Account","search_index":0,"allow_on_submit":0,"is_custom_field":null,"unique":0,"name":"d1d8185a25","idx":3,"doctype":"DocField","length":0,"fieldname":"account","fieldtype":"Link","options":"Account","report_hide":0,"parentfield":"fields"}],"docstatus":0,"sort_field":"modified","hide_toolbar":0,"allow_copy":0}]}

JS error:

VM1444:20 Uncaught TypeError: Cannot read property '0' of undefinedfrappe.call.callback @ VM1444:20callback @ desk.min.js:7280statusCode.200 @ desk.min.js:7282(anonymous function) @ desk.min.js:7288j @ jquery.min.js:2k.fireWith @ jquery.min.js:2x @ jquery.min.js:4(anonymous function) @ jquery.min.js:4

JS function:

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® {
var root = r.message[0][“value”];
erpnext.sales_chart = new erpnext.SalesChart(ctype, root, page,
page.main.css({
“min-height”: “300px”,
“padding-bottom”: “25px”
}));
}
});
}

The same error I got when navigate to Territory Tree. Any ideas how to fix it?

The result of the function get_children in sales_browser.py is empty list.

MariaDB [1bd3e0294d]> select * from tabCustomer Group;
Empty set (0.00 sec)

Have you deleted all customer groups manually?

No, I didn’t do any manipulations directly with database. How to add them? As I understand ERPNext should have migration to add them?

Seems like you have completed setup wizard before installing erpnext. And Setup process related to erpnext did not executed at all.

Raised an github issue: https://github.com/frappe/frappe/issues/1488

@Yevgen_Runts if you have done above steps
run bench reinstall from frappe-bench folder
This will delete all database of your current site and reinstall app erpnext and frappe.

Any way to run erpnext setup? Reinstall is not good solution cause it will delete all data.

My setup steps are:
wget https://raw.githubusercontent.com/frappe/bench/master/install_scripts/setup_frappe.sh
sudo bash setup_frappe.sh --skip-setup-bench
bench init frappe-bench && cd frappe-bench
bench get-app erpnext https://github.com/frappe/erpnext.git
bench new-site site1.local
bench install-app erpnext
bench start

I understand that I could just run sudo bash setup_frappe.sh but I want to do it by steps. Maybe I skipped some commands?