set root type from parent or child
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index aec889c..7ba57ab 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -48,17 +48,17 @@
def validate_parent(self):
"""Fetch Parent Details and validation for account not to be created under ledger"""
if self.doc.parent_account:
- par = frappe.db.sql("""select name, group_or_ledger, is_pl_account
- from tabAccount where name =%s""", self.doc.parent_account)
+ par = frappe.db.sql("""select name, group_or_ledger, root_type
+ from tabAccount where name =%s""", self.doc.parent_account, as_dict=1)
if not par:
throw(_("Parent account does not exists"))
- elif par[0][0] == self.doc.name:
+ elif par[0]["name"] == self.doc.name:
throw(_("You can not assign itself as parent account"))
- elif par[0][1] != 'Group':
+ elif par[0]["group_or_ledger"] != 'Group':
throw(_("Parent account can not be a ledger"))
-
- if not self.doc.is_pl_account:
- self.doc.is_pl_account = par[0][2]
+
+ if par[0]["root_type"]:
+ self.doc.root_type = par[0]["root_type"]
def validate_duplicate_account(self):
if self.doc.fields.get('__islocal') or not self.doc.name:
diff --git a/erpnext/accounts/doctype/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/doctype/chart_of_accounts/chart_of_accounts.py
index 819adb4..050cc3f 100644
--- a/erpnext/accounts/doctype/chart_of_accounts/chart_of_accounts.py
+++ b/erpnext/accounts/doctype/chart_of_accounts/chart_of_accounts.py
@@ -10,6 +10,7 @@
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
+ self.no_root_type = False
def create_accounts(self, company):
chart = {}
@@ -35,22 +36,28 @@
"parent_account": parent,
"group_or_ledger": "Group" if child.get("children") else "Ledger",
"root_type": child.get("root_type"),
- "is_pl_account": "Yes" if child.get("root_type") in ["Expense", "Income"] \
- else "No",
"account_type": child.get("account_type")
}).insert()
accounts.append(account_name_in_db)
- # print account.doc.lft, account.doc.rgt, account.doc.root_type
-
+
+ # set root_type for all parents where blank
+ if not account.doc.root_type or account.doc.root_type == 'None':
+ self.no_root_type = True
+ elif self.no_root_type:
+ frappe.db.sql("""update tabAccount set root_type=%s
+ where lft<=%s and rgt>=%s and ifnull(root_type, '')=''""",
+ (account.doc.root_type, account.doc.lft, account.doc.rgt))
+
if child.get("children"):
_import_accounts(child.get("children"), account.doc.name)
_import_accounts(chart.get("root").get("children"), None)
-
- # set root_type from parent or child if not set
- # root_types = frappe.db.sql("""select lft, rgt, distinct root_type from tabAccount
- # where ifnull(root_type, '') != '' order by lft desc""")
- # print root_types
-
-
\ No newline at end of file
+
+ # set root_type for root accounts
+ for acc in frappe.db.sql("""select name, lft, rgt from `tabAccount`
+ where ifnull(parent_account, '')=''""", as_dict=1):
+ root_types = frappe.db.sql_list("""select distinct root_type from tabAccount
+ where lft>%s and rgt<%s""", (acc.lft, acc.rgt))
+ if len(root_types) > 1:
+ frappe.db.set_value("Account", acc.name, "root_type", None)
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/chart_of_accounts/charts/import_from_openerp.py b/erpnext/accounts/doctype/chart_of_accounts/charts/import_from_openerp.py
index f8cecc8..c37cdef 100644
--- a/erpnext/accounts/doctype/chart_of_accounts/charts/import_from_openerp.py
+++ b/erpnext/accounts/doctype/chart_of_accounts/charts/import_from_openerp.py
@@ -220,7 +220,7 @@
accounts[account["parent_id"]]["children"].append(account)
del account["parent_id"]
else:
- print account.get("name")
+ print account.get("name") + " deleted, parent node not found"
del accounts[id]
# remove empty children
diff --git a/erpnext/setup/doctype/company/test_company.py b/erpnext/setup/doctype/company/test_company.py
index 1fd87af..482ba1d 100644
--- a/erpnext/setup/doctype/company/test_company.py
+++ b/erpnext/setup/doctype/company/test_company.py
@@ -10,8 +10,8 @@
def test_coa(self):
for country, chart_name in frappe.db.sql("""select country, chart_name
from `tabChart of Accounts` order by country""", as_list=1):
- print country
- # print "Chart Name: ", chart_name
+ print "Country: ", country
+ print "Chart Name: ", chart_name
company_bean = frappe.bean({
"doctype": "Company",
diff --git a/erpnext/stock/doctype/item/item.txt b/erpnext/stock/doctype/item/item.txt
index 51abc22..229fa97 100644
--- a/erpnext/stock/doctype/item/item.txt
+++ b/erpnext/stock/doctype/item/item.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-05-03 10:45:46",
"docstatus": 0,
- "modified": "2014-03-05 15:20:59",
+ "modified": "2014-03-13 15:54:09",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -31,7 +31,6 @@
},
{
"cancel": 0,
- "delete": 0,
"doctype": "DocPerm",
"email": 1,
"name": "__common__",
@@ -274,7 +273,7 @@
"doctype": "DocField",
"fieldname": "is_asset_item",
"fieldtype": "Select",
- "label": "Is Asset Item",
+ "label": "Is Fixed Asset Item",
"oldfieldname": "is_asset_item",
"oldfieldtype": "Select",
"options": "Yes\nNo",
@@ -868,6 +867,7 @@
},
{
"create": 1,
+ "delete": 1,
"doctype": "DocPerm",
"import": 1,
"role": "Material Master Manager",
@@ -876,6 +876,7 @@
{
"amend": 0,
"create": 0,
+ "delete": 0,
"doctype": "DocPerm",
"role": "Material Manager",
"write": 0
@@ -883,6 +884,7 @@
{
"amend": 0,
"create": 0,
+ "delete": 0,
"doctype": "DocPerm",
"role": "Material User",
"write": 0