Rename duplicate account
This commit is contained in:
parent
fc37fd8b6e
commit
3dfe854108
@ -3,22 +3,34 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe, os, json
|
import frappe, os, json
|
||||||
|
from frappe.utils import cstr
|
||||||
|
from unidecode import unidecode
|
||||||
|
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
self.doc, self.doclist = d, dl
|
self.doc, self.doclist = d, dl
|
||||||
|
|
||||||
def create_accounts(self, company):
|
def create_accounts(self, company):
|
||||||
|
chart = {}
|
||||||
with open(os.path.join(os.path.dirname(__file__), "charts",
|
with open(os.path.join(os.path.dirname(__file__), "charts",
|
||||||
self.doc.source_file), "r") as f:
|
self.doc.source_file), "r") as f:
|
||||||
chart = json.loads(f.read())
|
chart = json.loads(f.read())
|
||||||
|
|
||||||
|
if chart:
|
||||||
|
accounts = []
|
||||||
def _import_accounts(children, parent):
|
def _import_accounts(children, parent):
|
||||||
for child in children:
|
for child in children:
|
||||||
print child.get("name"), parent
|
account_name = child.get("name")
|
||||||
|
account_name_in_db = unidecode(account_name.strip().lower())
|
||||||
|
|
||||||
|
if account_name_in_db in accounts:
|
||||||
|
count = accounts.count(account_name_in_db)
|
||||||
|
account_name = account_name + " " + cstr(count)
|
||||||
|
|
||||||
account = frappe.bean({
|
account = frappe.bean({
|
||||||
"doctype": "Account",
|
"doctype": "Account",
|
||||||
"account_name": child.get("name"),
|
"account_name": account_name,
|
||||||
"company": company,
|
"company": company,
|
||||||
"parent_account": parent,
|
"parent_account": parent,
|
||||||
"group_or_ledger": "Group" if child.get("children") else "Ledger",
|
"group_or_ledger": "Group" if child.get("children") else "Ledger",
|
||||||
@ -28,7 +40,17 @@ class DocType:
|
|||||||
"account_type": child.get("account_type")
|
"account_type": child.get("account_type")
|
||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
|
accounts.append(account_name_in_db)
|
||||||
|
# print account.doc.lft, account.doc.rgt, account.doc.root_type
|
||||||
|
|
||||||
if child.get("children"):
|
if child.get("children"):
|
||||||
_import_accounts(child.get("children"), account.doc.name)
|
_import_accounts(child.get("children"), account.doc.name)
|
||||||
|
|
||||||
_import_accounts(chart.get("root").get("children"), None)
|
_import_accounts(chart.get("root").get("children"), None)
|
||||||
|
|
||||||
|
# set root_type from parent or child if not set
|
||||||
|
# root_types = frappe.db.sql("""select lft, rgt, distinct root_type from tabAccount
|
||||||
|
# where ifnull(root_type, '') != '' order by lft desc""")
|
||||||
|
# print root_types
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user