From 1977322c47e5c6cea39a58a8ecbda6dcb77ba0c2 Mon Sep 17 00:00:00 2001 From: samdanikouser Date: Sun, 3 Nov 2024 14:50:10 +0300 Subject: [PATCH 1/5] civil id assurance validation from dss --- one_fm/hooks.py | 3 +++ one_fm/overrides/employee.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/one_fm/hooks.py b/one_fm/hooks.py index 931bff2e4..0fae5f07b 100644 --- a/one_fm/hooks.py +++ b/one_fm/hooks.py @@ -436,6 +436,9 @@ "OAuth Bearer Token": { "after_insert": "one_fm.api.doc_methods.oauth_bearer_token.revoke_and_delete_existing_tokens", }, + "Employee": { + "before_save": "one_fm.overrides.employee.get_assurance_level_of_employee" + } } standard_portal_menu_items = [ diff --git a/one_fm/overrides/employee.py b/one_fm/overrides/employee.py index a79a54b34..f2c8d75ca 100644 --- a/one_fm/overrides/employee.py +++ b/one_fm/overrides/employee.py @@ -1,5 +1,6 @@ from itertools import chain from json import loads +import requests import frappe from frappe.utils import getdate, add_days, get_url_to_form, get_url @@ -553,3 +554,24 @@ def toggle_auto_attendance(employee_names: list | str, status: bool): except Exception as e: frappe.log_error(title = f"{str(e)}",message = frappe.get_traceback()) return response(message=str(e), status_code=400) + + +def get_assurance_level_of_employee(doc, method): + if doc.one_fm_civil_id: + print("samdani") + print(doc.one_fm_civil_id) + civil_id = doc.one_fm_civil_id + url = f"http://192.168.11.13:8080/api/DigitalSigning/CheckMobileIdentity/{civil_id}" + try: + response = requests.get(url) + if response.status_code == 200: + data = response.json() + print(data) + verification_level = data["data"].get("verificationLevel") + doc.custom_civil_id_assurance_level = verification_level + frappe.msgprint(f"Verification level stored successfully: {verification_level}") + else: + frappe.msgprint(f"API call failed with status code: {response.status_code}") + except Exception as e: + frappe.log_error(message=str(e), title="API Call Failed") + frappe.msgprint(f"An error occurred while making the API call: {str(e)}") From c275c68ae9ac1264346221ed2308bf16ade37c40 Mon Sep 17 00:00:00 2001 From: samdanikouser Date: Wed, 6 Nov 2024 10:34:40 +0300 Subject: [PATCH 2/5] doctype changes on employee and leave application --- one_fm/one_fm/custom/employee.json | 2 +- one_fm/one_fm/custom/leave_application.json | 123 +++++++++++++++----- 2 files changed, 96 insertions(+), 29 deletions(-) diff --git a/one_fm/one_fm/custom/employee.json b/one_fm/one_fm/custom/employee.json index 3d01b3c83..65c8591b5 100644 --- a/one_fm/one_fm/custom/employee.json +++ b/one_fm/one_fm/custom/employee.json @@ -1262,7 +1262,7 @@ "print_hide": 0, "print_hide_if_no_value": 0, "print_width": null, - "read_only": 0, + "read_only": 1, "read_only_depends_on": null, "report_hide": 0, "reqd": 0, diff --git a/one_fm/one_fm/custom/leave_application.json b/one_fm/one_fm/custom/leave_application.json index aa0b9d006..78c037068 100644 --- a/one_fm/one_fm/custom/leave_application.json +++ b/one_fm/one_fm/custom/leave_application.json @@ -1,5 +1,72 @@ { "custom_fields": [ + { + "_assign": null, + "_comments": null, + "_liked_by": null, + "_user_tags": null, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "collapsible_depends_on": null, + "columns": 0, + "creation": "2024-11-06 10:27:26.011840", + "default": null, + "depends_on": null, + "description": null, + "docstatus": 0, + "dt": "Leave Application", + "fetch_from": "employee.custom_civil_id_assurance_level", + "fetch_if_empty": 0, + "fieldname": "custom_employee_civil_id_assurance_level", + "fieldtype": "Data", + "hidden": 0, + "hide_border": 0, + "hide_days": 0, + "hide_seconds": 0, + "idx": 4, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_preview": 0, + "in_standard_filter": 0, + "insert_after": "employee_name", + "is_system_generated": 0, + "is_virtual": 0, + "label": "Employee Civil ID Assurance Level", + "length": 0, + "link_filters": null, + "mandatory_depends_on": null, + "modified": "2024-11-06 10:27:26.011840", + "modified_by": "Administrator", + "module": null, + "name": "Leave Application-custom_employee_civil_id_assurance_level", + "no_copy": 0, + "non_negative": 0, + "options": null, + "owner": "Administrator", + "parent": null, + "parentfield": null, + "parenttype": null, + "permlevel": 0, + "placeholder": null, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": null, + "read_only": 1, + "read_only_depends_on": null, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "show_dashboard": 0, + "sort_options": 0, + "translatable": 0, + "unique": 0, + "width": null + }, { "_assign": null, "_comments": null, @@ -25,7 +92,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 20, + "idx": 21, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, @@ -92,7 +159,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 21, + "idx": 22, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, @@ -147,7 +214,7 @@ "columns": 0, "creation": "2024-10-31 15:32:25.595259", "default": null, - "depends_on": "eval:doc.status === 'Cancelled' || doc.status === 'Approved'", + "depends_on": "eval:doc.status === 'Cancelled'", "description": null, "docstatus": 0, "dt": "Leave Application", @@ -159,7 +226,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 18, + "idx": 19, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, @@ -226,7 +293,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 42, + "idx": 43, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, @@ -293,7 +360,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 35, + "idx": 36, "ignore_user_permissions": 1, "ignore_xss_filter": 0, "in_global_search": 0, @@ -360,7 +427,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 36, + "idx": 37, "ignore_user_permissions": 1, "ignore_xss_filter": 0, "in_global_search": 0, @@ -427,7 +494,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 41, + "idx": 42, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, @@ -494,7 +561,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 22, + "idx": 23, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, @@ -695,7 +762,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 9, + "idx": 10, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, @@ -762,7 +829,7 @@ "hide_border": 0, "hide_days": 0, "hide_seconds": 0, - "idx": 40, + "idx": 41, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_global_search": 0, @@ -889,7 +956,7 @@ "field_name": "description", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.261830", + "modified": "2024-11-06 10:20:13.831199", "modified_by": "Administrator", "module": null, "name": "Leave Application-description-read_only_depends_on", @@ -915,7 +982,7 @@ "field_name": "employee", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.288195", + "modified": "2024-11-06 10:20:13.848142", "modified_by": "Administrator", "module": null, "name": "Leave Application-employee-ignore_user_permissions", @@ -941,7 +1008,7 @@ "field_name": "employee", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.315923", + "modified": "2024-11-06 10:20:13.867461", "modified_by": "Administrator", "module": null, "name": "Leave Application-employee-read_only_depends_on", @@ -967,7 +1034,7 @@ "field_name": "follow_via_email", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.331207", + "modified": "2024-11-06 10:20:13.886929", "modified_by": "Administrator", "module": null, "name": "Leave Application-follow_via_email-default", @@ -993,7 +1060,7 @@ "field_name": "from_date", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.345946", + "modified": "2024-11-06 10:20:13.903709", "modified_by": "Administrator", "module": null, "name": "Leave Application-from_date-read_only_depends_on", @@ -1019,7 +1086,7 @@ "field_name": "half_day", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.360798", + "modified": "2024-11-06 10:20:13.919794", "modified_by": "Administrator", "module": null, "name": "Leave Application-half_day-read_only_depends_on", @@ -1045,7 +1112,7 @@ "field_name": "leave_approver", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.374373", + "modified": "2024-11-06 10:20:13.937902", "modified_by": "Administrator", "module": null, "name": "Leave Application-leave_approver-default", @@ -1071,7 +1138,7 @@ "field_name": "leave_approver", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.390987", + "modified": "2024-11-06 10:20:13.954055", "modified_by": "Administrator", "module": null, "name": "Leave Application-leave_approver-read_only_depends_on", @@ -1097,7 +1164,7 @@ "field_name": "leave_type", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.404793", + "modified": "2024-11-06 10:20:13.970371", "modified_by": "Administrator", "module": null, "name": "Leave Application-leave_type-read_only_depends_on", @@ -1115,7 +1182,7 @@ "_comments": null, "_liked_by": null, "_user_tags": null, - "creation": "2024-11-03 13:10:24.504036", + "creation": "2024-11-06 10:27:25.813900", "default_value": null, "doc_type": "Leave Application", "docstatus": 0, @@ -1123,7 +1190,7 @@ "field_name": null, "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 13:10:24.504036", + "modified": "2024-11-06 10:27:25.813900", "modified_by": "Administrator", "module": null, "name": "Leave Application-main-field_order", @@ -1134,7 +1201,7 @@ "property": "field_order", "property_type": "Data", "row_name": null, - "value": "[\"workflow_state\", \"naming_series\", \"employee\", \"employee_name\", \"column_break_4\", \"leave_type\", \"is_proof_document_required\", \"proof_document\", \"proof_documents\", \"company\", \"department\", \"section_break_5\", \"from_date\", \"to_date\", \"half_day\", \"half_day_date\", \"total_leave_days\", \"custom_reason_for_cancel\", \"column_break1\", \"custom_propose_from_date\", \"custom_propose_to_date\", \"custom_total_propose_leave_days\", \"description\", \"leave_balance\", \"section_break_7\", \"leave_approver\", \"leave_approver_name\", \"follow_via_email\", \"column_break_18\", \"posting_date\", \"status\", \"sb_other_details\", \"salary_slip\", \"color\", \"custom_reliever_\", \"custom_reliever_name\", \"column_break_17\", \"letter_head\", \"amended_from\", \"source\", \"custom_section_break_neyf8\", \"custom_reassigned_documents\"]" + "value": "[\"workflow_state\", \"naming_series\", \"employee\", \"employee_name\", \"employee_civil_id_assurance_level\", \"column_break_4\", \"leave_type\", \"is_proof_document_required\", \"proof_document\", \"proof_documents\", \"company\", \"department\", \"section_break_5\", \"from_date\", \"to_date\", \"half_day\", \"half_day_date\", \"total_leave_days\", \"custom_reason_for_cancel\", \"column_break1\", \"custom_propose_from_date\", \"custom_propose_to_date\", \"custom_total_propose_leave_days\", \"description\", \"leave_balance\", \"section_break_7\", \"leave_approver\", \"leave_approver_name\", \"follow_via_email\", \"column_break_18\", \"posting_date\", \"status\", \"sb_other_details\", \"salary_slip\", \"color\", \"custom_reliever_\", \"custom_reliever_name\", \"column_break_17\", \"letter_head\", \"amended_from\", \"source\", \"custom_section_break_neyf8\", \"custom_reassigned_documents\"]" }, { "_assign": null, @@ -1149,7 +1216,7 @@ "field_name": null, "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.438053", + "modified": "2024-11-06 10:20:14.005017", "modified_by": "Administrator", "module": null, "name": "Leave Application-main-max_attachments", @@ -1175,7 +1242,7 @@ "field_name": "naming_series", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.452278", + "modified": "2024-11-06 10:20:14.023809", "modified_by": "Administrator", "module": null, "name": "Leave Application-naming_series-options", @@ -1201,7 +1268,7 @@ "field_name": "status", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.464574", + "modified": "2024-11-06 10:20:14.042376", "modified_by": "Administrator", "module": null, "name": "Leave Application-status-read_only", @@ -1227,7 +1294,7 @@ "field_name": "status", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.478335", + "modified": "2024-11-06 10:20:14.066247", "modified_by": "Administrator", "module": null, "name": "Leave Application-status-read_only_depends_on", @@ -1253,7 +1320,7 @@ "field_name": "to_date", "idx": 0, "is_system_generated": 0, - "modified": "2024-11-03 11:22:30.493450", + "modified": "2024-11-06 10:20:14.091867", "modified_by": "Administrator", "module": null, "name": "Leave Application-to_date-read_only_depends_on", From a3705a5326909b32b3cd9b8fdea1eaaad2b21218 Mon Sep 17 00:00:00 2001 From: samdanikouser Date: Wed, 6 Nov 2024 14:26:44 +0300 Subject: [PATCH 3/5] bluk update of assurance level --- one_fm/hooks.py | 1 + one_fm/overrides/employee.py | 24 ++++++------------------ one_fm/utils.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/one_fm/hooks.py b/one_fm/hooks.py index bc2919416..8171cb2d8 100644 --- a/one_fm/hooks.py +++ b/one_fm/hooks.py @@ -561,6 +561,7 @@ "one_fm.developer.doctype.bug_buster.bug_buster.roster_bug_buster", 'one_fm.utils.set_employee_status_to_vacation', 'one_fm.utils.set_out_of_office_for_leaves', + 'one_fm.utils.update_active_employees_assurance_level' ], "hourly": [ # "one_fm.api.tasks.send_checkin_hourly_reminder", diff --git a/one_fm/overrides/employee.py b/one_fm/overrides/employee.py index f2c8d75ca..6d48153d7 100644 --- a/one_fm/overrides/employee.py +++ b/one_fm/overrides/employee.py @@ -16,7 +16,7 @@ is_subcontract_employee ) from one_fm.processor import sendemail,send_whatsapp -from one_fm.utils import get_domain, get_standard_notification_template, get_approver_user +from one_fm.utils import call_to_get_assurance_level, get_domain, get_standard_notification_template, get_approver_user, update_active_employees_assurance_level from six import string_types from frappe import _ from one_fm.operations.doctype.operations_shift.operations_shift import get_supervisor_operations_shifts @@ -556,22 +556,10 @@ def toggle_auto_attendance(employee_names: list | str, status: bool): return response(message=str(e), status_code=400) +@frappe.whitelist() def get_assurance_level_of_employee(doc, method): if doc.one_fm_civil_id: - print("samdani") - print(doc.one_fm_civil_id) - civil_id = doc.one_fm_civil_id - url = f"http://192.168.11.13:8080/api/DigitalSigning/CheckMobileIdentity/{civil_id}" - try: - response = requests.get(url) - if response.status_code == 200: - data = response.json() - print(data) - verification_level = data["data"].get("verificationLevel") - doc.custom_civil_id_assurance_level = verification_level - frappe.msgprint(f"Verification level stored successfully: {verification_level}") - else: - frappe.msgprint(f"API call failed with status code: {response.status_code}") - except Exception as e: - frappe.log_error(message=str(e), title="API Call Failed") - frappe.msgprint(f"An error occurred while making the API call: {str(e)}") + verification_level = call_to_get_assurance_level(doc.one_fm_civil_id) + doc.custom_civil_id_assurance_level = verification_level + return True + diff --git a/one_fm/utils.py b/one_fm/utils.py index d543a328e..9746c7546 100755 --- a/one_fm/utils.py +++ b/one_fm/utils.py @@ -3829,4 +3829,33 @@ def set_out_of_office_for_leaves(): if today == add_days(to_date, 1): disable_out_of_office(employee_email) +@frappe.whitelist() +def update_active_employees_assurance_level(): + today = datetime.now().date() + employees = frappe.get_all('Employee',filters=[['status','=','Active'],['one_fm_civil_id', '!=', '']],fields=['employee','one_fm_civil_id','custom_civil_id_assurance_level','civil_id_expiry_date']) + for i in employees: + verification_level = None + if i.custom_civil_id_assurance_level != 'High': + verification_level = call_to_get_assurance_level(i.one_fm_civil_id) + elif i.custom_civil_id_assurance_level == 'High' and i.civil_id_expiry_date <= today: + verification_level = call_to_get_assurance_level(i.one_fm_civil_id) + frappe.db.set_value('Employee', i.employee, 'custom_civil_id_assurance_level', verification_level) + frappe.db.commit() + return True + + +def call_to_get_assurance_level(civil_id): + url = f"http://192.168.11.13:8080/api/DigitalSigning/CheckMobileIdentity/{civil_id}" + try: + response = requests.get(url) + if response.status_code == 200: + data = response.json() + verification_level = data["data"].get("verificationLevel") + return verification_level + except Exception as e: + frappe.msgprint(f"An error occurred while making the API call: {str(e)}") + return response(message=str(e), title="API Call Failed") + + + From 5ec27cb8e996666de17dd7832834b196dc204813 Mon Sep 17 00:00:00 2001 From: samdanikouser Date: Wed, 6 Nov 2024 14:52:47 +0300 Subject: [PATCH 4/5] removing whitelist --- one_fm/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/one_fm/utils.py b/one_fm/utils.py index 9746c7546..998b72359 100755 --- a/one_fm/utils.py +++ b/one_fm/utils.py @@ -3829,7 +3829,7 @@ def set_out_of_office_for_leaves(): if today == add_days(to_date, 1): disable_out_of_office(employee_email) -@frappe.whitelist() + def update_active_employees_assurance_level(): today = datetime.now().date() employees = frappe.get_all('Employee',filters=[['status','=','Active'],['one_fm_civil_id', '!=', '']],fields=['employee','one_fm_civil_id','custom_civil_id_assurance_level','civil_id_expiry_date']) From eea895a190ea77d6e9e097006013a99eaaad1684 Mon Sep 17 00:00:00 2001 From: samdanikouser Date: Wed, 13 Nov 2024 13:10:41 +0300 Subject: [PATCH 5/5] blick update --- one_fm/utils.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/one_fm/utils.py b/one_fm/utils.py index f63ed0048..7821914ad 100755 --- a/one_fm/utils.py +++ b/one_fm/utils.py @@ -2,7 +2,7 @@ # encoding: utf-8 from __future__ import unicode_literals import os, json, math, pymysql, requests, datetime -from datetime import timedelta, datetime +from datetime import date, timedelta, datetime from dateutil.relativedelta import relativedelta from datetime import datetime import pandas as pd @@ -3832,29 +3832,39 @@ def set_out_of_office_for_leaves(): if today == add_days(to_date, 1): disable_out_of_office(employee_email) - +@frappe.whitelist() def update_active_employees_assurance_level(): today = datetime.now().date() employees = frappe.get_all('Employee',filters=[['status','=','Active'],['one_fm_civil_id', '!=', '']],fields=['employee','one_fm_civil_id','custom_civil_id_assurance_level','civil_id_expiry_date']) - for i in employees: - verification_level = None - if i.custom_civil_id_assurance_level != 'High': - verification_level = call_to_get_assurance_level(i.one_fm_civil_id) - elif i.custom_civil_id_assurance_level == 'High' and i.civil_id_expiry_date <= today: - verification_level = call_to_get_assurance_level(i.one_fm_civil_id) - frappe.db.set_value('Employee', i.employee, 'custom_civil_id_assurance_level', verification_level) - frappe.db.commit() - return True + for employee in employees: + if isinstance(employee.get("civil_id_expiry_date"), date): + employee["civil_id_expiry_date"] = employee["civil_id_expiry_date"].isoformat() + # payload = {"employees": employees} + verification_level = call_to_get_assurance_level(employees) + + # for i in employees: + # verification_level = None + # if i.custom_civil_id_assurance_level != 'High': + # verification_level = call_to_get_assurance_level(i.one_fm_civil_id) + # elif i.custom_civil_id_assurance_level == 'High' and i.civil_id_expiry_date <= today: + # verification_level = call_to_get_assurance_level(i.one_fm_civil_id) + # frappe.db.set_value('Employee', i.employee, 'custom_civil_id_assurance_level', verification_level) + # frappe.db.commit() + return verification_level -def call_to_get_assurance_level(civil_id): - url = f"http://192.168.11.13:8080/api/DigitalSigning/CheckMobileIdentity/{civil_id}" +def call_to_get_assurance_level(payload): + print("samdani") + json=payload + print(json) + url = f"http://192.168.11.13:8080/api/DigitalSigning/BulkCheckMobileIdentity" try: - response = requests.get(url) + response = requests.post(url, json=payload) + print("samdani response ") + print(response.status_code) if response.status_code == 200: data = response.json() - verification_level = data["data"].get("verificationLevel") - return verification_level + return data except Exception as e: frappe.msgprint(f"An error occurred while making the API call: {str(e)}") return response(message=str(e), title="API Call Failed")