From e64fbd6d3cfb1f95b693bb5e162a4e0d04154572 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 4 Jan 2016 18:11:03 +0530 Subject: [PATCH] [minor] fixes for chart_of_accounts_builder app --- .../chart_of_accounts/chart_of_accounts.py | 28 ++++++++++--------- erpnext/setup/doctype/company/company.py | 14 ++++++---- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py index bfb5240fa8..e1f9f1ce9c 100644 --- a/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py +++ b/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py @@ -82,24 +82,26 @@ def get_charts_for_country(country): def _get_chart_name(content): if content: content = json.loads(content) - if content and content.get("is_active", "No") == "Yes" and content.get("disabled", "No") == "No": + + if frappe.local.flags.allow_unverified_charts: + charts.append(content["name"]) + + elif content and content.get("is_active", "No") == "Yes" and content.get("disabled", "No") == "No": charts.append(content["name"]) country_code = frappe.db.get_value("Country", country, "code") if country_code: - path = os.path.join(os.path.dirname(__file__), "verified") - for fname in os.listdir(path): - if fname.startswith(country_code) and fname.endswith(".json"): - with open(os.path.join(path, fname), "r") as f: - _get_chart_name(f.read()) + folders = ("verified",) + if frappe.local.flags.allow_unverified_charts: + folders = ("verified", "unverified") - # countries_use_OHADA_system = ["Benin", "Burkina Faso", "Cameroon", "Central African Republic", "Comoros", - # "Congo", "Ivory Coast", "Gabon", "Guinea", "Guinea Bissau", "Equatorial Guinea", "Mali", "Niger", - # "Replica of Democratic Congo", "Senegal", "Chad", "Togo"] - # - # if country in countries_use_OHADA_system: - # with open(os.path.join(os.path.dirname(__file__), "syscohada_syscohada_chart_template.json"), "r") as f: - # _get_chart_name(f.read()) + for folder in folders: + path = os.path.join(os.path.dirname(__file__), folder) + + for fname in os.listdir(path): + if fname.startswith(country_code) and fname.endswith(".json"): + with open(os.path.join(path, fname), "r") as f: + _get_chart_name(f.read()) if len(charts) != 1: charts.append("Standard") diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index d337805344..120106aaa4 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -216,13 +216,15 @@ class Company(Document): frappe.db.sql("""delete from `tabItem Reorder` where warehouse in (%s)""" % ', '.join(['%s']*len(warehouses)), tuple(warehouses)) - for f in ["income_account", "expense_account"]: - frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)""" - % (f, f, ', '.join(['%s']*len(accounts))), tuple(accounts)) + if accounts: + for f in ["income_account", "expense_account"]: + frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)""" + % (f, f, ', '.join(['%s']*len(accounts))), tuple(accounts)) - for f in ["selling_cost_center", "buying_cost_center"]: - frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)""" - % (f, f, ', '.join(['%s']*len(cost_centers))), tuple(cost_centers)) + if cost_centers: + for f in ["selling_cost_center", "buying_cost_center"]: + frappe.db.sql("""update tabItem set %s=NULL where %s in (%s)""" + % (f, f, ', '.join(['%s']*len(cost_centers))), tuple(cost_centers)) # reset default company frappe.db.sql("""update `tabSingles` set value=""