diff --git a/onboarding/decorators.py b/onboarding/decorators.py index 584905a1a..a2ac20c5e 100644 --- a/onboarding/decorators.py +++ b/onboarding/decorators.py @@ -4,7 +4,8 @@ decorators.py Custom decorators for permission and manager checks in the application. """ from django.contrib import messages -from django.http import HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect +from django.shortcuts import render from employee.models import Employee from recruitment.models import Recruitment from onboarding.models import OnboardingTask,OnboardingStage @@ -70,7 +71,12 @@ def all_manager_can_enter(function, perm): if user.has_perm(perm) or is_manager: return function(request, *args, **kwargs) messages.info(request, "You dont have permission.") - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) + previous_url = request.META.get("HTTP_REFERER", "/") + script = f'' + key = "HTTP_HX_REQUEST" + if key in request.META.keys(): + return render(request,"decorator_404.html") + return HttpResponse(script) return _function @@ -91,7 +97,12 @@ def stage_manager_can_enter(function, perm): if user.has_perm(perm) or is_manager: return function(request, *args, **kwargs) messages.info(request, "You dont have permission.") - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) + previous_url = request.META.get("HTTP_REFERER", "/") + script = f'' + key = "HTTP_HX_REQUEST" + if key in request.META.keys(): + return render(request,"decorator_404.html") + return HttpResponse(script) return _function @@ -109,6 +120,11 @@ def recruitment_manager_can_enter(function, perm): if user.has_perm(perm) or is_manager: return function(request, *args, **kwargs) messages.info(request, "You dont have permission.") - return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/")) + previous_url = request.META.get("HTTP_REFERER", "/") + script = f'' + key = "HTTP_HX_REQUEST" + if key in request.META.keys(): + return render(request,"decorator_404.html") + return HttpResponse(script) return _function diff --git a/onboarding/models.py b/onboarding/models.py index 268f63449..4dda9e1db 100644 --- a/onboarding/models.py +++ b/onboarding/models.py @@ -12,6 +12,7 @@ from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ +from horilla_audit.models import HorillaAuditInfo, HorillaAuditLog from recruitment.models import Recruitment, Candidate from employee.models import Employee from base.horilla_company_manager import HorillaCompanyManager @@ -133,7 +134,6 @@ class CandidateTask(models.Model): """ choice = ( - ("", ""), ("todo", _("Todo")), ("scheduled", _("Scheduled")), ("ongoing", _("Ongoing")), @@ -155,6 +155,12 @@ class CandidateTask(models.Model): ) onboarding_task_id = models.ForeignKey(OnboardingTask, on_delete=models.PROTECT) objects = HorillaCompanyManager("candidate_id__recruitment_id__company_id") + history = HorillaAuditLog( + related_name="history_set", + bases=[ + HorillaAuditInfo, + ], + ) def __str__(self): return f"{self.candidate_id}|{self.onboarding_task_id}" diff --git a/onboarding/templates/onboarding/dashboard.html b/onboarding/templates/onboarding/dashboard.html index 430a6807e..b4f50ebf6 100644 --- a/onboarding/templates/onboarding/dashboard.html +++ b/onboarding/templates/onboarding/dashboard.html @@ -2,7 +2,23 @@ {% block content %} {% load static i18n %} {% load i18n %} - + @@ -120,6 +136,13 @@ {% endif %} + + diff --git a/onboarding/templates/onboarding/dashboard/status_list.html b/onboarding/templates/onboarding/dashboard/status_list.html new file mode 100644 index 000000000..edd396f83 --- /dev/null +++ b/onboarding/templates/onboarding/dashboard/status_list.html @@ -0,0 +1,61 @@ +{% load i18n %} + + {{ candidate_tasks.first.onboarding_task_id.task_title }} + + + + {% for task in candidate_tasks %} + + + + + + + {{ task.candidate_id.name }} + + + + {% for status in task.choice %} + {{status.1}} + {% endfor %} + + + + + {% endfor %} + + diff --git a/onboarding/templates/onboarding/dashboard/task_report.html b/onboarding/templates/onboarding/dashboard/task_report.html new file mode 100644 index 000000000..5780458dc --- /dev/null +++ b/onboarding/templates/onboarding/dashboard/task_report.html @@ -0,0 +1,68 @@ +{% load i18n %} + + + {% trans 'My Onboarding Tasks' %} + + {% if tasks %} + + + + + + + {% trans 'Task' %} + + + {% trans 'Todo' %} + + + {% trans 'Scheduled' %} + + + {% trans 'Ongoing' %} + + + {% trans 'Stuck' %} + + + {% trans 'Done' %} + + + + + {% for task in tasks %} + + + {{ task.task }} + ({{ task.total_candidates }}) + + {{ task.todo }} + {{ task.scheduled }} + {{ task.ongoing }} + {{ task.stuck }} + {{ task.done }} + + {% endfor %} + + + + + {% else %} + + + + {% trans 'No data Found...' %} + + + {% endif %} + + + + + + + + + + + \ No newline at end of file diff --git a/onboarding/urls.py b/onboarding/urls.py index a41b0af88..2d3cd5f27 100644 --- a/onboarding/urls.py +++ b/onboarding/urls.py @@ -125,5 +125,14 @@ urlpatterns = [ views.onboarding_send_mail, name="onboarding-send-mail", ), - path("update-probotion-end",views.update_probation_end,name="update-probotion-end") + path( + "update-probotion-end", views.update_probation_end, name="update-probotion-end" + ), + path("task-report-onboarding", views.task_report, name="task-report-onboarding"), + path( + "candidate-tasks-status", + views.candidate_tasks_status, + name="candidate-tasks-status", + ), + path("change-task-status", views.change_task_status, name="change-task-status"), ] diff --git a/onboarding/views.py b/onboarding/views.py index 5516a7356..c72f60717 100644 --- a/onboarding/views.py +++ b/onboarding/views.py @@ -29,7 +29,7 @@ from django.views.decorators.http import require_http_methods from base.models import JobPosition from notifications.signals import notify from horilla import settings -from horilla.decorators import login_required, hx_request_required, manager_can_enter +from horilla.decorators import login_required, hx_request_required from horilla.decorators import permission_required from base.methods import generate_pdf, get_key_instances, get_pagination, sortby from recruitment.models import Candidate, Recruitment, RecruitmentMailTemplate @@ -439,7 +439,7 @@ def candidate_delete(request, obj_id): @login_required -@manager_can_enter("onboarding.view_candidatestage") +@all_manager_can_enter("onboarding.view_candidatestage") def candidates_single_view(request, id, **kwargs): """ Candidate individual view for the onboarding candidates @@ -1535,3 +1535,69 @@ def update_probation_end(request): probation_end = request.GET["probation_end"] Candidate.objects.filter(id__in=candidate_id).update(probation_end=probation_end) return JsonResponse({"message": "Probation end date updated", "type": "success"}) + + +@login_required +@all_manager_can_enter("onboarding.change_onboardingtask") +def task_report(request): + """ + This method is used to show the task report. + """ + stage_id = request.GET.get("stage_id") + employee_id = request.GET.get("employee_id") + if not employee_id: + employee_id = request.user.employee_get.id + my_tasks = OnboardingTask.objects.filter( + employee_id__id=employee_id, + candidates__recruitment_id__closed=False, + ).distinct() + tasks = [] + for task in my_tasks: + tasks.append( + { + "task": task, + "total_candidates": task.candidatetask_set.count(), + "todo": task.candidatetask_set.filter(status="todo").count(), + "scheduled": task.candidatetask_set.filter(status="scheduled").count(), + "ongoing": task.candidatetask_set.filter(status="ongoing").count(), + "stuck": task.candidatetask_set.filter(status="stuck").count(), + "done": task.candidatetask_set.filter(status="done").count(), + } + ) + return render(request, "onboarding/dashboard/task_report.html", {"tasks": tasks}) + + +@login_required +@all_manager_can_enter("onboarding.view_candidatetask") +def candidate_tasks_status(request): + """ + This method is used to render template to show the onboarding tasks + """ + task_id = request.GET["task_id"] + candidate_tasks = CandidateTask.objects.filter(onboarding_task_id__id=task_id) + return render( + request, + "onboarding/dashboard/status_list.html", + {"candidate_tasks": candidate_tasks}, + ) + + +@login_required +@all_manager_can_enter("onboarding.change_candidatetask") +def change_task_status(request): + """ + This method is to update the candidate task + """ + task_id = request.GET["task_id"] + candidate_task = CandidateTask.objects.get(id=task_id) + status = request.GET["status"] + if status in [ + "todo", + "scheduled", + "ongoing", + "stuck", + "done", + ]: + candidate_task.status = status + candidate_task.save() + return HttpResponse("Success")