Skip to content

Commit

Permalink
Merge pull request #1 from navariltd/develop1
Browse files Browse the repository at this point in the history
fix - remove file and write data directly in employee checkin
  • Loading branch information
maniamartial authored Jul 23, 2024
2 parents 18fd8e2 + ab6da32 commit a4103c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
27 changes: 13 additions & 14 deletions navari_cams_biometric/cams_biometric/controllers/cams_call.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import frappe
from frappe import _
from datetime import datetime
from dateutil import parser

@frappe.whitelist(allow_guest=True)
Expand Down Expand Up @@ -35,18 +34,6 @@ def attendance():

def handle_attendance_log(stgid, rawdata):
request_data = json.loads(rawdata)
print(str(request_data))

content = f'ServiceTagId: {stgid},\t'
content += f'UserId: {request_data["RealTime"]["PunchLog"]["UserId"]},\t'
content += f'AttendanceTime: {request_data["RealTime"]["PunchLog"]["LogTime"]},\t'
content += f'AttendanceType: {request_data["RealTime"]["PunchLog"]["Type"]},\t'
content += f'InputType: {request_data["RealTime"]["PunchLog"]["InputType"]},\t'
content += f'Operation: RealTime->PunchLog,\t'
content += f'AuthToken: {request_data["RealTime"]["AuthToken"]}\n'

with open("cams-attendance-record.txt", "a") as file:
file.write(content)

log_type_punch = request_data["RealTime"]["PunchLog"]["Type"]
log_type = 'OUT' if log_type_punch == 'CheckOut' else 'IN'
Expand All @@ -55,17 +42,29 @@ def handle_attendance_log(stgid, rawdata):
log_time = request_data["RealTime"]["PunchLog"]["LogTime"]
log_time_dt = parser.parse(log_time)
formatted_log_time = log_time_dt.strftime("%Y-%m-%d %H:%M:%S")
print("Time is", str(formatted_log_time))

# Storing the values in Employee Checking doctype
employee_checking = frappe.get_doc({
"doctype": "Employee Checkin",
"employee": request_data["RealTime"]["PunchLog"]["UserId"],
"time": formatted_log_time,
"log_type": log_type,
"custom_input_type":request_data["RealTime"]["PunchLog"]["InputType"]
})

employee_checking.insert(ignore_permissions=True)
frappe.db.commit()

return "done"

'''I dont see the need to write to a file'''
# content = f'ServiceTagId: {stgid},\t'
# content += f'UserId: {request_data["RealTime"]["PunchLog"]["UserId"]},\t'
# content += f'AttendanceTime: {request_data["RealTime"]["PunchLog"]["LogTime"]},\t'
# content += f'AttendanceType: {request_data["RealTime"]["PunchLog"]["Type"]},\t'
# content += f'InputType: {request_data["RealTime"]["PunchLog"]["InputType"]},\t'
# content += f'Operation: RealTime->PunchLog,\t'
# content += f'AuthToken: {request_data["RealTime"]["AuthToken"]}\n'

# with open("cams-attendance-record.txt", "a") as file:
# file.write(content)
17 changes: 17 additions & 0 deletions navari_cams_biometric/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
app_description = "///\'.\'"
app_email = "[email protected]"
app_license = "agpl-3.0"


fixtures = [
{
"doctype": "Custom Field",
"filters": [
[
"name",
"in",
(
"Employee Checkin-custom_input_type",

),
]
],
},
]
# required_apps = []

# Includes in <head>
Expand Down

0 comments on commit a4103c7

Please sign in to comment.