import chart records into database frm json

This commit is contained in:
Nabin Hait 2014-03-06 18:21:56 +05:30
parent a69c30edec
commit 813a93d78d
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,26 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe, os, json
def import_charts():
frappe.db.sql("""delete from `tabChart of Accounts`""")
charts_dir = os.path.join(os.path.dirname(__file__), "charts")
for fname in os.listdir(charts_dir):
if fname.endswith(".json"):
with open(os.path.join(charts_dir, fname), "r") as f:
chart = json.loads(f.read())
country = frappe.db.get_value("Country", {"code": fname.split("_", 1)[0]})
if country:
bean = frappe.bean({
"doctype":"Chart of Accounts",
"chart_name": chart.get("name"),
"source_file": fname,
"country": country
}).insert()
print bean.doc.name
else:
print "No chart for: " + chart.get("name")
frappe.db.commit()

View File

@ -8,6 +8,8 @@ import frappe
def after_install():
import_defaults()
import_country_and_currency()
from erpnext.accounts.doctype.chart_of_accounts.import_charts import import_charts
import_charts()
frappe.db.set_value('Control Panel', None, 'home_page', 'setup-wizard')
feature_setup()
from erpnext.setup.page.setup_wizard.setup_wizard import add_all_roles_to
@ -24,6 +26,7 @@ def import_country_and_currency():
frappe.doc({
"doctype": "Country",
"country_name": name,
"code": country.code,
"date_format": country.date_format or "dd-mm-yyyy",
"time_zones": "\n".join(country.timezones or [])
}).insert()