Hi All,
I need notification when user checkin in the employee checkin transaction at the time of holidays (holiday list) it should get a email notification
Thanks in Advance
that for, you have to create a server logic and set it.
it means server script??
Thanks in Advance
Yes … !
If you want to reminder of holiday then check the image. but your case is different so you have to create a server script for that and add your logic.
import frappe
from frappe.utils import getdate, formatdate
@frappe.whitelist()
def check_holiday_and_notify(employee, checkin_time):
# Get employee’s holiday list
employee_doc = frappe.get_doc(“Employee”, employee)
holiday_list = employee_doc.holiday_list
# Get check-in date
checkin_date = getdate(checkin_time)
# Check if the check-in date is a holiday
if is_holiday(holiday_list, checkin_date):
# Send email notification
send_email_notification(employee_doc, checkin_date, checkin_time)
return 'holiday'
return 'not_holiday'
def is_holiday(holiday_list, date):
holidays = frappe.get_all(“Holiday”, filters={“parent”: holiday_list, “holiday_date”: date})
return len(holidays) > 0
def send_email_notification(employee, checkin_date, checkin_time):
recipients = [“dwarak@biz.cloudreign.in”] # Replace with the actual recipient email addresses
subject = f"Employee {employee.employee_name} Check-in on Holiday"
message = f"“”
Employee {employee.employee_name} (ID: {employee.name}) checked in on {formatdate(checkin_date)} at {checkin_time}.
Please take the necessary actions.
“”"
frappe.sendmail(
recipients=recipients,
subject=subject,
message=message
)
this server script is okk??
Test it, yourself. if worked then server script is okay
doctype event which need to keep?? for this server script ?
Thanks in Advance
are you using the frapp.call from the js side? you have to use API
App Versions
{
"erpnext": "14.37.1",
"frappe": "14.47.2",
"hrms": "15.0.0-dev",
"india_compliance": "14.16.2",
"payments": "0.0.1"
}
Route
Form/Employee Checkin/new-employee-checkin-3
Traceback
Traceback (most recent call last):
File "apps/frappe/frappe/app.py", line 94, in application
response = frappe.api.handle()
File "apps/frappe/frappe/api.py", line 54, in handle
return frappe.handler.handle()
File "apps/frappe/frappe/handler.py", line 47, in handle
data = execute_cmd(cmd)
File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "apps/frappe/frappe/__init__.py", line 1622, in call
return fn(*args, **newargs)
File "apps/frappe/frappe/desk/form/save.py", line 28, in savedocs
doc.save()
File "apps/frappe/frappe/model/document.py", line 307, in save
return self._save(*args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 329, in _save
return self.insert()
File "apps/frappe/frappe/model/document.py", line 261, in insert
self.run_before_save_methods()
File "apps/frappe/frappe/model/document.py", line 1053, in run_before_save_methods
self.run_method("validate")
File "apps/frappe/frappe/model/document.py", line 921, in run_method
run_server_script_for_doc_event(self, method)
File "apps/frappe/frappe/core/doctype/server_script/server_script_utils.py", line 39, in run_server_script_for_doc_event
frappe.get_doc("Server Script", script_name).execute_doc(doc)
File "apps/frappe/frappe/core/doctype/server_script/server_script.py", line 106, in execute_doc
safe_exec(self.script, _locals={"doc": doc}, restrict_commit_rollback=True)
File "apps/frappe/frappe/utils/safe_exec.py", line 85, in safe_exec
exec(
File "<serverscript>", line 1, in <module>
ImportError: __import__ not found
Request Data
{
"type": "POST",
"args": {
"doc": "{\"docstatus\":0,\"doctype\":\"Employee Checkin\",\"name\":\"new-employee-checkin-1\",\"__islocal\":1,\"__unsaved\":1,\"owner\":\"Administrator\",\"log_type\":\"IN\",\"time\":\"2024-07-14 09:00:00\",\"skip_auto_attendance\":0,\"employee_name\":\"Srividya Lakshminarayanan\",\"employee\":\"Srividya\"}",
"action": "Save"
},
"btn": {
"jQuery360062520895046993271": {
"events": {
"click": [
{
"type": "click",
"origType": "click",
"guid": 6216,
"namespace": ""
}
]
}
}
},
"freeze": true,
"headers": {},
"error_handlers": {},
"url": "/api/method/frappe.desk.form.save.savedocs"
}
Response Data
{
"exception": "ImportError: __import__ not found"
}
this error is coming bro
Thanks in Advance
You have to apply it in your custom app. because import does not work in the server script doctype.
Reference: