feature(chart-of-accounts): Rebuild HSM Tree after bulk insertion (#15457)

* feature(chart-of-accounts): Rebuild HSM Tree after bulk insertion

* Update chart_of_accounts.py
This commit is contained in:
Aditya Hase 2018-09-25 18:10:50 +05:30 committed by Nabin Hait
parent b113349f31
commit a38b77cbfd
2 changed files with 11 additions and 0 deletions

View File

@ -12,6 +12,11 @@ class BalanceMismatchError(frappe.ValidationError): pass
class Account(NestedSet):
nsm_parent_field = 'parent_account'
def on_update(self):
if frappe.local.flags.ignore_on_update:
return
else:
super().on_update()
def onload(self):
frozen_accounts_modifier = frappe.db.get_value("Accounts Settings", "Accounts Settings",

View File

@ -6,6 +6,7 @@ import frappe, os, json
from frappe.utils import cstr
from unidecode import unidecode
from six import iteritems
from frappe.utils.nestedset import rebuild_tree
def create_charts(company, chart_template=None, existing_company=None):
chart = get_chart(chart_template, existing_company)
@ -53,7 +54,12 @@ def create_charts(company, chart_template=None, existing_company=None):
_import_accounts(child, account.name, root_type)
# Rebuild NestedSet HSM tree for Account Doctype
# after all accounts are already inserted.
frappe.local.flags.ignore_on_update = True
_import_accounts(chart, None, None, root_account=True)
rebuild_tree("Account", "parent_account")
frappe.local.flags.ignore_on_update = False
def add_suffix_if_duplicate(account_name, account_number, accounts):
if account_number: