when self.name will be available, getting error while trying to use self.name in validate doctype event
so my question is in which doctype events self.name is available?
class ServiceDesk(Document):
def validate(self):
frappe.msgprint(f"name in validate: {self.name}")
frappe.msgprint(f"status: {self.docstatus}")
def before_insert(self):
# if self.docstatus > 0:
frappe.msgprint(f"status > 0: {self.docstatus}")
frappe.msgprint(f"name: {self.name}")
if not self.name:
frappe.throw(_("The name of the document is not set."))
if self.doctype == "Service Desk":
project_name = _(self.name) + " : " + self.branch
frappe.msgprint("creating project")
project = frappe.get_doc(
{
"doctype": "Project",
"project_name": project_name,
# "expected_start_date": self.date_of_joining
# if self.doctype == "Employee Onboarding"
# else self.resignation_letter_date,
# "department": self.department,
# "company": self.company,
}
).insert(ignore_permissions=True, ignore_mandatory=True)
frappe.msgprint(" project created")
self.db_set("project", project.name)
self.reload()
self.create_task_and_notify_user()
def assign_task_to_users(self, task, users):
for user in users:
args = {
"assign_to": [user],
"doctype": task.doctype,
"name": task.name,
"description": task.description or task.subject,
# "notify": self.notify_users_by_email,
}
assign_to.add(args)
def create_task_and_notify_user(self):
task_assignments = self.assigned_to
for task_assignment in task_assignments:
frappe.msgprint(f"assigned to: {task_assignment}")
frappe.msgprint(f"assigned to: {task_assignment.task_name}")
frappe.msgprint("creating task")
task = frappe.get_doc(
{
"doctype": "Task",
"project": self.project,
"subject": task_assignment.task_name + " : " + self.name,
"description": task_assignment.task_description,
# "department": self.department,
# "company": self.company,
# "task_weight": activity.task_weight,
"issue": self.name,
# "exp_start_date": frappe.utils.data.nowtime(),
"exp_start_date": frappe.utils.nowdate(),
# "exp_end_date": dates[1],
}
).insert(ignore_permissions=True)
frappe.msgprint("task created")
users = [task_assignment.assign_to] if task_assignment.assign_to else []
# if activity.role:
# user_list = frappe.db.sql_list(
# """
# SELECT
# DISTINCT(has_role.parent)
# FROM
# `tabHas Role` has_role
# LEFT JOIN `tabUser` user
# ON has_role.parent = user.name
# WHERE
# has_role.parenttype = 'User'
# AND user.enabled = 1
# AND has_role.role = %s
# """,
# activity.role,
# )
# users = unique(users + user_list)
# if "Administrator" in users:
# users.remove("Administrator")
# assign the task the users
if users:
self.assign_task_to_users(task, users)
getting error ‘The name of the document is not set’ when trying to get name in before_insert doctype event
what is the issue and in which doctypes self.name is available