diff --git a/employee/methods/methods.py b/employee/methods/methods.py index 1c5d1a00e..1b804cd04 100644 --- a/employee/methods/methods.py +++ b/employee/methods/methods.py @@ -2,10 +2,12 @@ employee/methods.py """ -from datetime import date, datetime, timedelta +import threading +from datetime import datetime from itertools import groupby import pandas as pd +from django.apps import apps from django.contrib.auth.models import User from django.db import models @@ -35,6 +37,9 @@ def convert_nan(field, dicts): def dynamic_prefix_sort(item): + """ + Sorts items based on a dynamic prefix length. + """ # Assuming the dynamic prefix length is 3 prefix = get_initial_prefix(None)["get_initial_prefix"] @@ -88,6 +93,14 @@ def get_ordered_badge_ids(): def check_relationship_with_employee_model(model): + """ + Checks the relationship of a given model with the Employee model. + + This function iterates through all the fields of the specified model + and identifies fields that are either `ForeignKey` or `ManyToManyField` + and are related to the `Employee` model. For each such field, it adds + the field name and the type of relationship to a list. + """ related_fields = [] for field in model._meta.get_fields(): # Check if the field is a ForeignKey or ManyToManyField and related to Employee @@ -173,6 +186,14 @@ def bulk_create_employee_import(success_lists): def optimize_reporting_manager_lookup(success_lists): + """ + Optimizes the lookup of reporting managers from a list of work information. + + This function identifies unique reporting manager names from the provided + list of work information, queries all matching `Employee` objects in a + single database query, and creates a dictionary for quick lookups based + on the full name of the reporting managers. + """ # Step 1: Collect unique reporting manager names unique_managers = set() for work_info in success_lists: @@ -358,6 +379,34 @@ def bulk_create_employee_types(success_lists): EmployeeType.objects.bulk_create(employee_type_obj_list) +def create_contracts_in_thread(new_work_info_list, update_work_info_list): + """ + Creates employee contracts in bulk based on provided work information. + """ + from payroll.models.models import Contract + + def get_or_none(value): + return value if value else None + + contracts_list = [ + Contract( + contract_name=f"{work_info.employee_id}'s Contract", + employee_id=work_info.employee_id, + contract_start_date=datetime.today(), + department=get_or_none(work_info.department_id), + job_position=get_or_none(work_info.job_position_id), + job_role=get_or_none(work_info.job_role_id), + shift=get_or_none(work_info.shift_id), + work_type=get_or_none(work_info.work_type_id), + wage=work_info.basic_salary or 0, + ) + for work_info in new_work_info_list + update_work_info_list + if work_info.employee_id + ] + + Contract.objects.bulk_create(contracts_list) + + def bulk_create_work_info_import(success_lists): """ Bulk creation of employee work info instances based on the excel import of employees @@ -541,3 +590,10 @@ def bulk_create_work_info_import(success_lists): "salary_hour", ], ) + if apps.is_installed("payroll"): + + contract_creation_thread = threading.Thread( + target=create_contracts_in_thread, + args=(new_work_info_list, update_work_info_list), + ) + contract_creation_thread.start() diff --git a/employee/templates/disciplinary_actions/disciplinary_nav.html b/employee/templates/disciplinary_actions/disciplinary_nav.html index 10bb65770..851c50cda 100644 --- a/employee/templates/disciplinary_actions/disciplinary_nav.html +++ b/employee/templates/disciplinary_actions/disciplinary_nav.html @@ -113,7 +113,7 @@ {% if data %}
@@ -174,9 +174,6 @@ }, }); } else { - let dynamicActionType = $("#dynamicActionType"); - var view = parentForm.serialize(); - dynamicActionType.attr("hx-vals", `{"data":"${view}"}`); dynamicActionType.click(); } } diff --git a/employee/views.py b/employee/views.py index f1c0df611..bd6abe7d9 100755 --- a/employee/views.py +++ b/employee/views.py @@ -192,10 +192,6 @@ def employee_profile(request): This method is used to view own profile of employee. """ employee = request.user.employee_get - # interviews = InterviewSchedule.objects.filter(employee_id=employee).order_by( - # "-interview_date" - # ) - interviews = None today = datetime.today() now = timezone.now() return render( @@ -203,10 +199,7 @@ def employee_profile(request): "employee/profile/profile_view.html", { "employee": employee, - "user_leaves": None, - "leave_request_ids": json.dumps([]), "current_date": today, - "interviews": interviews, "now": now, }, )