When Add Employee Birth Day I Need to Reflect Direct in Calendar
In Employee Doctype
Can you explain a bit more about where you are adding the birthday and how you want it to be fetched automatically in the Employee doctype?
I Want to when Create Employee and his Birthday Added
the Day oh his Birthday Assigned to Events and display the Birthdays of this month on Home Desk
I hope I explained it well.
Here’s a sample code: when a user creates a new employee, it will automatically create an Event. If email is configured, it will send a notification at the event time.
Add the code in the server script doctype:
Script Type: DocType Event
Reference Document Type: Employee
DocType Event: After Save
if doc.date_of_birth:
birthday = frappe.utils.get_datetime(doc.date_of_birth)
current_year = frappe.utils.now_datetime().year
today = frappe.utils.now_datetime()
event_date = birthday.replace(year=current_year)
if event_date < today:
event_date = birthday.replace(year=current_year + 1)
existing_event = frappe.get_all("Event", filters={
"starts_on": event_date,
"subject": f"Birthday: {doc.employee_name}"
})
if not existing_event:
frappe.get_doc({
"doctype": "Event",
"subject": f"Birthday: {doc.employee_name}",
"starts_on": event_date,
"description": f"Celebrating {doc.employee_name}'s birthday",
"all_day": 1
}).insert()
Now you can to set the logic and customize it your way according to the scenario.
Thank You