Creating custom unique user id that is tied to a user account

I am working on the Students Admissions (School Management System) process in the Education module of ERPNext and I want to create unique student’s id for each student that is tied to the users account.

I have tried figuring out how to implement this but my approach is not doing what I want; I created a custom form field, hide that field, made it read only, added the field to the web form and when the forms are submitted, the admin can manually add the student’s id and that record will go to the database.

Hi,

Below is the sample code, you may modify as per your requirement. This code create the User account from the student form.

from frappe.utils import get_url_to_form
from frappe import _
from frappe.model.document import Document

class StudentForm(Document):
    def after_insert(self):
        def after_insert(self):
            user = frappe.new_doc("User")
            user. email = self.email
            user.first_name = self.first_name
            user.last_name = self.last_name
            user.save()

Thank you so much @mangroliya .
I don’t want to create a new user account after a student submits the form because users accounts have been created before students can access the form.
On the admissions letter generation, I want to generate a student id for each student automatically and include the id on their letter.

Look forward to hearing from you again.