Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Employee checking from response #6

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions navari_frappehr_biostar/controllers/biostar_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def get_attendance_report(
)

if response.status_code == 200:

"""no more records, break loop"""
if not response.json()["records"]:
if self.attendance_logs:
Expand Down Expand Up @@ -167,33 +168,15 @@ def create_punch_logs(self):

@frappe.whitelist()
def send_to_erpnext(employee_field_value, timestamp, log_type):
headers = {
"Authorization": "token " + api_key + ":" + api_secret,
"Accept": "application/json",
}

request_body = {
"employee_field_value": employee_field_value,
"timestamp": timestamp.__str__(),
"log_type": log_type,
}

send_to_erpnext_url = f"{erpnext_instance_url}/api/method/hrms.hr.doctype.employee_checkin.employee_checkin.add_log_based_on_employee_field"

employee_=frappe.get_doc("Employee", {"attendance_device_id": employee_field_value})
try:
response = requests.post(
send_to_erpnext_url, data=request_body, headers=headers
)

if response.status_code == 200:
frappe.log(f"Success: {str(response.json())}")
else:
frappe.msgprint(
f"Syncing attendance logs failed with status code: {response.status_code}"
)
new_employee_checkin=frappe.new_doc("Employee Checkin")
new_employee_checkin.employee=employee_.name
new_employee_checkin.log_type=log_type
new_employee_checkin.time=timestamp
new_employee_checkin.save()
except Exception as e:
frappe.throw(f"An error occurred: {e}")

frappe.log(f"An error occurred: {e}")

def is_cookie_expired(cookie_string):
"""parse cookie string"""
Expand Down
2 changes: 1 addition & 1 deletion navari_frappehr_biostar/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
scheduler_events = {

"cron":{
"0 0 * * *":["navari_frappehr_biostar.controllers.biostar_calls.add_checkin_logs_for_current_day"],
"10 23 * * *":["navari_frappehr_biostar.controllers.biostar_calls.add_checkin_logs_for_current_day"],
},
}

8 changes: 4 additions & 4 deletions navari_frappehr_biostar/public/js/fetch_list.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
frappe.listview_settings['Employee'].onload = function(listview) {
listview.page.add_action_item(__("Fetch Attendance"), function() {
submit_bulk_invoice(listview, "Employee");
submit_employee_list(listview, "Employee");
});
};

function submit_bulk_invoice(listview, doctype) {
function submit_employee_list(listview, doctype) {
let names = [];
$.each(listview.get_checked_items(), function(key, value) {
names.push(value.name);
Expand All @@ -21,7 +21,7 @@ function submit_bulk_invoice(listview, doctype) {
label: 'Start Date',
fieldname: 'start_date',
fieldtype: 'Date',
default: frappe.datetime.nowdate(), // Use frappe.datetime.nowdate() if custom_last_attendance_sync_date is not available
default: frappe.datetime.nowdate(),
reqd: 1
},
{
Expand All @@ -34,7 +34,7 @@ function submit_bulk_invoice(listview, doctype) {
primary_action_label: 'Fetch',
primary_action: function(data) {
d.hide();
let loader = document.getElementById('loader'); // Ensure loader element exists
let loader = document.getElementById('loader');
if (loader) {
loader.style.display = "block";
}
Expand Down
Loading