diff --git a/setup/doctype/setup_control/setup_control.py b/setup/doctype/setup_control/setup_control.py index 0f4f6a1e703..60d295735a0 100644 --- a/setup/doctype/setup_control/setup_control.py +++ b/setup/doctype/setup_control/setup_control.py @@ -271,7 +271,7 @@ def create_territories(): country = webnotes.conn.get_value("Control Panel", None, "country") root_territory = get_root_of("Territory") for name in (country, "Rest Of The World"): - if not webnotes.conn.exists("Territory", name): + if name and not webnotes.conn.exists("Territory", name): webnotes.bean({ "doctype": "Territory", "territory_name": name, diff --git a/setup/utils.py b/setup/utils.py index 04c4527cecb..c343ed1db1e 100644 --- a/setup/utils.py +++ b/setup/utils.py @@ -32,14 +32,15 @@ def get_company_currency(company): def get_root_of(doctype): """Get root element of a DocType with a tree structure""" result = webnotes.conn.sql_list("""select name from `tab%s` - where lft=1 and rgt=(select max(rgt) from `tab%s`)""" % (doctype, doctype)) + where lft=1 and rgt=(select max(rgt) from `tab%s` where docstatus < 2)""" % + (doctype, doctype)) return result[0] if result else None def get_ancestors_of(doctype, name): """Get ancestor elements of a DocType with a tree structure""" lft, rgt = webnotes.conn.get_value(doctype, name, ["lft", "rgt"]) result = webnotes.conn.sql_list("""select name from `tab%s` - where lft<%s and rgt>%s""" % (doctype, "%s", "%s"), (lft, rgt)) + where lft<%s and rgt>%s and docstatus < 2""" % (doctype, "%s", "%s"), (lft, rgt)) return result or None @webnotes.whitelist()