Skip to content

Commit

Permalink
Merge pull request #27967 from deepeshgarg007/account_name_number_error
Browse files Browse the repository at this point in the history
fix: Account number and name incorrectly imported using COA importer
  • Loading branch information
deepeshgarg007 authored Oct 18, 2021
2 parents 46e8009 + 17a8649 commit 9c54d6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from unidecode import unidecode


def create_charts(company, chart_template=None, existing_company=None, custom_chart=None):
def create_charts(company, chart_template=None, existing_company=None, custom_chart=None, from_coa_importer=None):
chart = custom_chart or get_chart(chart_template, existing_company)
if chart:
accounts = []
Expand All @@ -22,7 +22,7 @@ def _import_accounts(children, parent, root_type, root_account=False):
if root_account:
root_type = child.get("root_type")

if account_name not in ["account_number", "account_type",
if account_name not in ["account_name", "account_number", "account_type",
"root_type", "is_group", "tax_rate"]:

account_number = cstr(child.get("account_number")).strip()
Expand All @@ -35,7 +35,7 @@ def _import_accounts(children, parent, root_type, root_account=False):

account = frappe.get_doc({
"doctype": "Account",
"account_name": account_name,
"account_name": child.get('account_name') if from_coa_importer else account_name,
"company": company,
"parent_account": parent,
"is_group": is_group,
Expand Down Expand Up @@ -213,7 +213,7 @@ def _get_account_names(account_master):
return (bank_account in accounts)

@frappe.whitelist()
def build_tree_from_json(chart_template, chart_data=None):
def build_tree_from_json(chart_template, chart_data=None, from_coa_importer=False):
''' get chart template from its folder and parse the json to be rendered as tree '''
chart = chart_data or get_chart(chart_template)

Expand All @@ -226,9 +226,12 @@ def _import_accounts(children, parent):
''' recursively called to form a parent-child based list of dict from chart template '''
for account_name, child in iteritems(children):
account = {}
if account_name in ["account_number", "account_type",\
if account_name in ["account_name", "account_number", "account_type",\
"root_type", "is_group", "tax_rate"]: continue

if from_coa_importer:
account_name = child['account_name']

account['parent_account'] = parent
account['expandable'] = True if identify_is_group(child) else False
account['value'] = (cstr(child.get('account_number')).strip() + ' - ' + account_name) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def import_coa(file_name, company):

frappe.local.flags.ignore_root_company_validation = True
forest = build_forest(data)
create_charts(company, custom_chart=forest)
create_charts(company, custom_chart=forest, from_coa_importer=True)

# trigger on_update for company to reset default accounts
set_default_accounts(company)
Expand Down Expand Up @@ -148,7 +148,7 @@ def get_coa(doctype, parent, is_root=False, file_name=None, for_validate=0):

if not for_validate:
forest = build_forest(data)
accounts = build_tree_from_json("", chart_data=forest) # returns a list of dict in a tree render-able form
accounts = build_tree_from_json("", chart_data=forest, from_coa_importer=True) # returns a list of dict in a tree render-able form

# filter out to show data for the selected node only
accounts = [d for d in accounts if d['parent_account']==parent]
Expand Down Expand Up @@ -212,11 +212,14 @@ def return_parent(data, child):
if not account_name:
error_messages.append("Row {0}: Please enter Account Name".format(line_no))

name = account_name
if account_number:
account_number = cstr(account_number).strip()
account_name = "{} - {}".format(account_number, account_name)

charts_map[account_name] = {}
charts_map[account_name]['account_name'] = name
if account_number: charts_map[account_name]["account_number"] = account_number
if cint(is_group) == 1: charts_map[account_name]["is_group"] = is_group
if account_type: charts_map[account_name]["account_type"] = account_type
if root_type: charts_map[account_name]["root_type"] = root_type
Expand Down

0 comments on commit 9c54d6d

Please sign in to comment.