Included standard charts in json format

This commit is contained in:
Nabin Hait
2014-11-12 11:06:55 +05:30
parent 4963ac2af5
commit 4cd60d7d61
3 changed files with 616 additions and 15 deletions

View File

@@ -9,6 +9,8 @@ from unidecode import unidecode
def create_charts(chart_name, company): def create_charts(chart_name, company):
chart = get_chart(chart_name) chart = get_chart(chart_name)
frappe.db.sql("delete from `tabAccount` where company=%s", company)
if chart: if chart:
accounts = [] accounts = []
@@ -45,16 +47,20 @@ def create_charts(chart_name, company):
_import_accounts(children, account.name, root_type) _import_accounts(children, account.name, root_type)
_import_accounts(chart.get("tree"), None, None, root_account=True) _import_accounts(chart, None, None, root_account=True)
def get_chart(chart_name): def get_chart(chart_name):
chart = {} chart = {}
for fname in os.listdir(os.path.dirname(__file__)): if chart_name == "Standard":
if fname.endswith(".json"): from erpnext.accounts.doctype.account.chart_of_accounts import standard_chart_of_accounts
with open(os.path.join(os.path.dirname(__file__), fname), "r") as f: return standard_chart_of_accounts.coa
chart = f.read() else:
if chart and json.loads(chart).get("name") == chart_name: for fname in os.listdir(os.path.dirname(__file__)):
return json.loads(chart) if fname.endswith(".json"):
with open(os.path.join(os.path.dirname(__file__), fname), "r") as f:
chart = f.read()
if chart and json.loads(chart).get("name") == chart_name:
return json.loads(chart).get("tree")
@frappe.whitelist() @frappe.whitelist()
def get_charts_for_country(country): def get_charts_for_country(country):
@@ -80,4 +86,5 @@ def get_charts_for_country(country):
with open(os.path.join(os.path.dirname(__file__), "syscohada_syscohada_chart_template.json"), "r") as f: with open(os.path.join(os.path.dirname(__file__), "syscohada_syscohada_chart_template.json"), "r") as f:
_get_chart_name(f.read()) _get_chart_name(f.read())
charts.append("Standard")
return charts return charts

View File

@@ -0,0 +1,592 @@
{
"_(\"Accounts Payable\")": {
"_(\"Creditors\")": {
"account_type": "Payable"
}
},
"_(\"Accounts Receivable\")": {
"_(\"Debtors\")": {
"account_type": "Receivable"
}
},
"_(\"Administrative Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Application of Funds (Assets)\")": {
"_(\"Current Assets\")": {
"_(\"Accounts Receivable\")": {
"_(\"Debtors\")": {
"account_type": "Receivable"
}
},
"_(\"Bank Accounts\")": {
"account_type": "Bank"
},
"_(\"Cash In Hand\")": {
"_(\"Cash\")": {
"account_type": "Cash"
},
"account_type": "Cash"
},
"_(\"Loans and Advances (Assets)\")": {},
"_(\"Securities and Deposits\")": {
"_(\"Earnest Money\")": {}
},
"_(\"Stock Assets\")": {
"account_type": "Stock"
},
"_(\"Tax Assets\")": {}
},
"_(\"Fixed Assets\")": {
"_(\"Capital Equipments\")": {
"account_type": "Fixed Asset"
},
"_(\"Computers\")": {
"account_type": "Fixed Asset"
},
"_(\"Furniture and Fixture\")": {
"account_type": "Fixed Asset"
},
"_(\"Office Equipments\")": {
"account_type": "Fixed Asset"
},
"_(\"Plant and Machinery\")": {
"account_type": "Fixed Asset"
}
},
"_(\"Investments\")": {},
"_(\"Temporary Accounts (Assets)\")": {
"_(\"Temporary Assets\")": {}
}
},
"_(\"Bank Accounts\")": {
"account_type": "Bank"
},
"_(\"Bank Overdraft Account\")": {},
"_(\"Capital Account\")": {
"_(\"Reserves and Surplus\")": {},
"_(\"Shareholders Funds\")": {}
},
"_(\"Capital Equipments\")": {
"account_type": "Fixed Asset"
},
"_(\"Cash In Hand\")": {
"_(\"Cash\")": {
"account_type": "Cash"
},
"account_type": "Cash"
},
"_(\"Cash\")": {
"account_type": "Cash"
},
"_(\"Charity and Donations\")": {
"account_type": "Expense Account"
},
"_(\"Commission on Sales\")": {
"account_type": "Expense Account"
},
"_(\"Computers\")": {
"account_type": "Fixed Asset"
},
"_(\"Cost of Goods Sold\")": {
"account_type": "Expense Account"
},
"_(\"Creditors\")": {
"account_type": "Payable"
},
"_(\"Current Assets\")": {
"_(\"Accounts Receivable\")": {
"_(\"Debtors\")": {
"account_type": "Receivable"
}
},
"_(\"Bank Accounts\")": {
"account_type": "Bank"
},
"_(\"Cash In Hand\")": {
"_(\"Cash\")": {
"account_type": "Cash"
},
"account_type": "Cash"
},
"_(\"Loans and Advances (Assets)\")": {},
"_(\"Securities and Deposits\")": {
"_(\"Earnest Money\")": {}
},
"_(\"Stock Assets\")": {
"account_type": "Stock"
},
"_(\"Tax Assets\")": {}
},
"_(\"Current Liabilities\")": {},
"_(\"Debtors\")": {
"account_type": "Receivable"
},
"_(\"Depreciation\")": {
"account_type": "Expense Account"
},
"_(\"Direct Expenses\")": {
"_(\"Stock Expenses\")": {
"_(\"Cost of Goods Sold\")": {
"account_type": "Expense Account"
},
"_(\"Expenses Included In Valuation\")": {
"account_type": "Expenses Included In Valuation"
},
"_(\"Stock Adjustment\")": {
"account_type": "Stock Adjustment"
},
"account_type": "Expense Account"
},
"account_type": "Expense Account"
},
"_(\"Direct Income\")": {
"_(\"Sales\")": {
"account_type": "Income Account"
},
"_(\"Service\")": {
"account_type": "Income Account"
},
"account_type": "Income Account"
},
"_(\"Duties and Taxes\")": {},
"_(\"Earnest Money\")": {},
"_(\"Entertainment Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Expenses Included In Valuation\")": {
"account_type": "Expenses Included In Valuation"
},
"_(\"Expenses\")": {
"_(\"Direct Expenses\")": {
"_(\"Stock Expenses\")": {
"_(\"Cost of Goods Sold\")": {
"account_type": "Expense Account"
},
"_(\"Expenses Included In Valuation\")": {
"account_type": "Expenses Included In Valuation"
},
"_(\"Stock Adjustment\")": {
"account_type": "Stock Adjustment"
},
"account_type": "Expense Account"
},
"account_type": "Expense Account"
},
"_(\"Indirect Expenses\")": {
"_(\"Administrative Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Charity and Donations\")": {
"account_type": "Expense Account"
},
"_(\"Commission on Sales\")": {
"account_type": "Expense Account"
},
"_(\"Depreciation\")": {
"account_type": "Expense Account"
},
"_(\"Entertainment Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Freight and Forwarding Charges\")": {
"account_type": "Chargeable"
},
"_(\"Legal Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Marketing Expenses\")": {
"account_type": "Chargeable"
},
"_(\"Miscellaneous Expenses\")": {
"account_type": "Chargeable"
},
"_(\"Office Maintenance Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Office Rent\")": {
"account_type": "Expense Account"
},
"_(\"Postal Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Print and Stationary\")": {
"account_type": "Expense Account"
},
"_(\"Rounded Off\")": {
"account_type": "Expense Account"
},
"_(\"Salary\")": {
"account_type": "Expense Account"
},
"_(\"Sales Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Telephone Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Travel Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Utility Expenses\")": {
"account_type": "Expense Account"
},
"account_type": "Expense Account"
},
"account_type": "Expense Account"
},
"_(\"Fixed Assets\")": {
"_(\"Capital Equipments\")": {
"account_type": "Fixed Asset"
},
"_(\"Computers\")": {
"account_type": "Fixed Asset"
},
"_(\"Furniture and Fixture\")": {
"account_type": "Fixed Asset"
},
"_(\"Office Equipments\")": {
"account_type": "Fixed Asset"
},
"_(\"Plant and Machinery\")": {
"account_type": "Fixed Asset"
}
},
"_(\"Freight and Forwarding Charges\")": {
"account_type": "Chargeable"
},
"_(\"Furniture and Fixture\")": {
"account_type": "Fixed Asset"
},
"_(\"Income\")": {
"_(\"Direct Income\")": {
"_(\"Sales\")": {
"account_type": "Income Account"
},
"_(\"Service\")": {
"account_type": "Income Account"
},
"account_type": "Income Account"
},
"_(\"Indirect Income\")": {
"account_type": "Income Account"
}
},
"_(\"Indirect Expenses\")": {
"_(\"Administrative Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Charity and Donations\")": {
"account_type": "Expense Account"
},
"_(\"Commission on Sales\")": {
"account_type": "Expense Account"
},
"_(\"Depreciation\")": {
"account_type": "Expense Account"
},
"_(\"Entertainment Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Freight and Forwarding Charges\")": {
"account_type": "Chargeable"
},
"_(\"Legal Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Marketing Expenses\")": {
"account_type": "Chargeable"
},
"_(\"Miscellaneous Expenses\")": {
"account_type": "Chargeable"
},
"_(\"Office Maintenance Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Office Rent\")": {
"account_type": "Expense Account"
},
"_(\"Postal Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Print and Stationary\")": {
"account_type": "Expense Account"
},
"_(\"Rounded Off\")": {
"account_type": "Expense Account"
},
"_(\"Salary\")": {
"account_type": "Expense Account"
},
"_(\"Sales Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Telephone Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Travel Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Utility Expenses\")": {
"account_type": "Expense Account"
},
"account_type": "Expense Account"
},
"_(\"Indirect Income\")": {
"account_type": "Income Account"
},
"_(\"Investments\")": {},
"_(\"Legal Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Loans (Liabilities)\")": {},
"_(\"Loans and Advances (Assets)\")": {},
"_(\"Marketing Expenses\")": {
"account_type": "Chargeable"
},
"_(\"Miscellaneous Expenses\")": {
"account_type": "Chargeable"
},
"_(\"Office Equipments\")": {
"account_type": "Fixed Asset"
},
"_(\"Office Maintenance Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Office Rent\")": {
"account_type": "Expense Account"
},
"_(\"Plant and Machinery\")": {
"account_type": "Fixed Asset"
},
"_(\"Postal Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Print and Stationary\")": {
"account_type": "Expense Account"
},
"_(\"Reserves and Surplus\")": {},
"_(\"Rounded Off\")": {
"account_type": "Expense Account"
},
"_(\"Salary\")": {
"account_type": "Expense Account"
},
"_(\"Sales Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Sales\")": {
"account_type": "Income Account"
},
"_(\"Secured Loans\")": {},
"_(\"Securities and Deposits\")": {
"_(\"Earnest Money\")": {}
},
"_(\"Service\")": {
"account_type": "Income Account"
},
"_(\"Shareholders Funds\")": {},
"_(\"Source of Funds (Liabilities)\")": {
"_(\"Capital Account\")": {
"_(\"Reserves and Surplus\")": {},
"_(\"Shareholders Funds\")": {}
},
"_(\"Current Liabilities\")": {},
"_(\"Temporary Accounts (Liabilities)\")": {
"_(\"Temporary Liabilities\")": {}
}
},
"_(\"Stock Adjustment\")": {
"account_type": "Stock Adjustment"
},
"_(\"Stock Assets\")": {
"account_type": "Stock"
},
"_(\"Stock Expenses\")": {
"_(\"Cost of Goods Sold\")": {
"account_type": "Expense Account"
},
"_(\"Expenses Included In Valuation\")": {
"account_type": "Expenses Included In Valuation"
},
"_(\"Stock Adjustment\")": {
"account_type": "Stock Adjustment"
},
"account_type": "Expense Account"
},
"_(\"Stock Liabilities\")": {},
"_(\"Stock Received But Not Billed\")": {
"account_type": "Stock Received But Not Billed"
},
"_(\"Tax Assets\")": {},
"_(\"Telephone Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Temporary Accounts (Assets)\")": {
"_(\"Temporary Assets\")": {}
},
"_(\"Temporary Accounts (Liabilities)\")": {
"_(\"Temporary Liabilities\")": {}
},
"_(\"Temporary Assets\")": {},
"_(\"Temporary Liabilities\")": {},
"_(\"Travel Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Unsecured Loans\")": {},
"_(\"Utility Expenses\")": {
"account_type": "Expense Account"
},
"root": {
"_(\"Application of Funds (Assets)\")": {
"_(\"Current Assets\")": {
"_(\"Accounts Receivable\")": {
"_(\"Debtors\")": {
"account_type": "Receivable"
}
},
"_(\"Bank Accounts\")": {
"account_type": "Bank"
},
"_(\"Cash In Hand\")": {
"_(\"Cash\")": {
"account_type": "Cash"
},
"account_type": "Cash"
},
"_(\"Loans and Advances (Assets)\")": {},
"_(\"Securities and Deposits\")": {
"_(\"Earnest Money\")": {}
},
"_(\"Stock Assets\")": {
"account_type": "Stock"
},
"_(\"Tax Assets\")": {}
},
"_(\"Fixed Assets\")": {
"_(\"Capital Equipments\")": {
"account_type": "Fixed Asset"
},
"_(\"Computers\")": {
"account_type": "Fixed Asset"
},
"_(\"Furniture and Fixture\")": {
"account_type": "Fixed Asset"
},
"_(\"Office Equipments\")": {
"account_type": "Fixed Asset"
},
"_(\"Plant and Machinery\")": {
"account_type": "Fixed Asset"
}
},
"_(\"Investments\")": {},
"_(\"Temporary Accounts (Assets)\")": {
"_(\"Temporary Assets\")": {}
}
},
"_(\"Expenses\")": {
"_(\"Direct Expenses\")": {
"_(\"Stock Expenses\")": {
"_(\"Cost of Goods Sold\")": {
"account_type": "Expense Account"
},
"_(\"Expenses Included In Valuation\")": {
"account_type": "Expenses Included In Valuation"
},
"_(\"Stock Adjustment\")": {
"account_type": "Stock Adjustment"
},
"account_type": "Expense Account"
},
"account_type": "Expense Account"
},
"_(\"Indirect Expenses\")": {
"_(\"Administrative Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Charity and Donations\")": {
"account_type": "Expense Account"
},
"_(\"Commission on Sales\")": {
"account_type": "Expense Account"
},
"_(\"Depreciation\")": {
"account_type": "Expense Account"
},
"_(\"Entertainment Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Freight and Forwarding Charges\")": {
"account_type": "Chargeable"
},
"_(\"Legal Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Marketing Expenses\")": {
"account_type": "Chargeable"
},
"_(\"Miscellaneous Expenses\")": {
"account_type": "Chargeable"
},
"_(\"Office Maintenance Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Office Rent\")": {
"account_type": "Expense Account"
},
"_(\"Postal Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Print and Stationary\")": {
"account_type": "Expense Account"
},
"_(\"Rounded Off\")": {
"account_type": "Expense Account"
},
"_(\"Salary\")": {
"account_type": "Expense Account"
},
"_(\"Sales Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Telephone Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Travel Expenses\")": {
"account_type": "Expense Account"
},
"_(\"Utility Expenses\")": {
"account_type": "Expense Account"
},
"account_type": "Expense Account"
},
"account_type": "Expense Account"
},
"_(\"Income\")": {
"_(\"Direct Income\")": {
"_(\"Sales\")": {
"account_type": "Income Account"
},
"_(\"Service\")": {
"account_type": "Income Account"
},
"account_type": "Income Account"
},
"_(\"Indirect Income\")": {
"account_type": "Income Account"
}
},
"_(\"Source of Funds (Liabilities)\")": {
"_(\"Capital Account\")": {
"_(\"Reserves and Surplus\")": {},
"_(\"Shareholders Funds\")": {}
},
"_(\"Current Liabilities\")": {},
"_(\"Temporary Accounts (Liabilities)\")": {
"_(\"Temporary Liabilities\")": {}
}
},
"root_type": "true"
}
}

View File

@@ -49,11 +49,11 @@ class Company(Document):
.format(self.get(field), self.name)) .format(self.get(field), self.name))
def on_update(self): def on_update(self):
if not frappe.db.sql("""select name from tabAccount # if not frappe.db.sql("""select name from tabAccount
where company=%s and docstatus<2 limit 1""", self.name): # where company=%s and docstatus<2 limit 1""", self.name):
self.create_default_accounts() self.create_default_accounts()
self.create_default_warehouses() self.create_default_warehouses()
self.install_country_fixtures() self.install_country_fixtures()
if not frappe.db.get_value("Cost Center", {"group_or_ledger": "Ledger", "company": self.name}): if not frappe.db.get_value("Cost Center", {"group_or_ledger": "Ledger", "company": self.name}):
self.create_default_cost_center() self.create_default_cost_center()
@@ -81,11 +81,13 @@ class Company(Document):
}).insert() }).insert()
def create_default_accounts(self): def create_default_accounts(self):
if self.chart_of_accounts: if not self.chart_of_accounts:
frappe.throw(_("Please select Chart of Accounts"))
else:
from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import create_charts from erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts import create_charts
create_charts(self.chart_of_accounts, self.name) create_charts(self.chart_of_accounts, self.name)
else: # else:
self.create_standard_accounts() # self.create_standard_accounts()
frappe.db.set(self, "default_receivable_account", frappe.db.get_value("Account", frappe.db.set(self, "default_receivable_account", frappe.db.get_value("Account",
{"company": self.name, "account_type": "Receivable"})) {"company": self.name, "account_type": "Receivable"}))