Attendance on ERP Login

Hello !!

We can submit the attendance of the current user, as soon as the user login.
each activity stored a new record in the Activity log, so on successful login activity, we can trigger submit attendance.

    if doc.operation == 'Login':
    employee_name_for_auto_attandenace = doc.full_name
    today_attendance_date = frappe.utils.today()
    frappe.get_doc(dict(
    doctype = 'Attendance',
    employee_name = 'employee_name_for_auto_attandenace',
    attendance_date = today_attendance_date
    )).submit()
    frappe.msgprint(msg=('Attendance for ' + doc.full_name + 'has been created'))
3 Likes

Hey Patel,
is it works?

Yes, It worked.
But for some user, it gives the error because the user’s name and employee name didn’t match like user’s name full name: Meet, employee full name: Meetkumar Patel, for this I need to fetch employee name or set equal name in the user name and employee name.
@nomanhaider

Where to put this code ?

server script doctype

Reference Document Type ??

Capture

1 Like

Hi @Meet_Patel it says Please Enable Server Scripts

bench --site site1.local set-config server_script_enabled true

SyntaxError: (“Line 1: SyntaxError: invalid character in identifier at statement: ‘if doc.operation == ‘Login’:’”,)

Yea,
If you are using Frappe Cloud, you can find in site config. or if you are on own server, I think you need to setup in site_config.json file
@dineshpanchal432

1 Like

It has been resolved using below command

bench --site site1.local set-config server_script_enabled true

After being enabled, It doesnt let me log in. It just says “verifying…” and doesnt log me in.
server scripts are enabled

This is the error @Meet_Patel

SyntaxError: ("Line 1: SyntaxError: invalid character in identifier at statement: 'if doc.operation == ‘Login’:'",)

share Screenshot of page @Sidhk

Nice to know. Thank you.

I guess you mean ~/frappe-bench/sites/common_site_config.json ?

Yes, I think we can get in common_site_config.json