Char Account Number Auto number in V-14

Hello ,
First of all, thank you for an amazing product.

I am working in erpnext 14 version
1-Can I make the Account number filed Automatically?
2 - Also when we add new child or sub account the number should completely related to the main account number for example if the main account number is 101 the first child number should be 101001
and the second child number should be 101002
the third child 1001003

please guide me how to do it.
thanks.

Hi @Hamza_Erpnext,

might be it can be possible using server script logic but it can be done only if you create a new account from list view, not in the tree view.

1 Like

@NCP
Thanks

Hello @Hamza_Erpnext, were you able to make it work? If so, can you please give me some insight on how?

Server Script

parentaccount=doc.parent_account
#try:
query_result = frappe.db.sql("""
        SELECT  Max(creation) FROM `tabAccount`
        WHERE parent_account = %s 
    """, parentaccount)
#frappe.errprint(query_result)
frappe.errprint(query_result[0][0])
if query_result and  query_result[0][0] is not None:
   frappe.errprint('in')
   lastinsertedaccountdate = query_result[0][0]
   accountnumber = frappe.db.sql("""
      SELECT  Max(account_number) FROM `tabAccount`
        WHERE creation = %s 
    """, lastinsertedaccountdate)[0][0] or 0
   frappe.errprint(accountnumber)
   acc=int(accountnumber)+1
   doc.account_number=acc
    
    
else:
    frappe.errprint('else')
    lastinsertedaccountdate = 1
    #=doc.parent_account
    accountnumber = frappe.db.sql("""
      SELECT  account_number FROM `tabAccount`
        WHERE name = %s 
    """, parentaccount)[0][0] or 0
    acc=accountnumber+'001'
    doc.account_number=acc
    
    frappe.errprint(accountnumber)
    
frappe.errprint('exitn')   
frappe.errprint(accountnumber)
#acc=int(accountnumber)+1
#frappe.errprint(acc+1)
#doc.account_number=acc
#frappe.errprint(lastinsertedaccountdate)

1 Like

@LittleDaggers27

thank you, much appreciated