[UPDT] RECRUITMENT: Added employee document from candidate conversion to employee
This commit is contained in:
@@ -1001,7 +1001,9 @@ class CandidateDocumentRequest(HorillaModel):
|
||||
|
||||
class CandidateDocument(HorillaModel):
|
||||
title = models.CharField(max_length=250)
|
||||
candidate_id = models.ForeignKey(Candidate, on_delete=models.PROTECT)
|
||||
candidate_id = models.ForeignKey(
|
||||
Candidate, on_delete=models.PROTECT, verbose_name="Candidate"
|
||||
)
|
||||
document_request_id = models.ForeignKey(
|
||||
CandidateDocumentRequest, on_delete=models.PROTECT, null=True
|
||||
)
|
||||
|
||||
@@ -61,6 +61,7 @@ from horilla.decorators import (
|
||||
permission_required,
|
||||
)
|
||||
from horilla.group_by import group_by_queryset
|
||||
from horilla_documents.models import Document
|
||||
from notifications.signals import notify
|
||||
from recruitment.auth import CandidateAuthenticationBackend
|
||||
from recruitment.decorators import (
|
||||
@@ -1666,22 +1667,23 @@ def candidate_conversion(request, cand_id, **kwargs):
|
||||
if not candidate_obj:
|
||||
messages.error(request, _("Candidate not found"))
|
||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
||||
can_name = candidate_obj.name
|
||||
can_mob = candidate_obj.mobile
|
||||
can_job = candidate_obj.job_position_id
|
||||
can_dep = can_job.department_id
|
||||
can_mail = candidate_obj.email
|
||||
can_gender = candidate_obj.gender
|
||||
can_company = candidate_obj.recruitment_id.company_id
|
||||
user_exists = User.objects.filter(username=can_mail).exists()
|
||||
cand_name = candidate_obj.name
|
||||
cand_mob = candidate_obj.mobile
|
||||
cand_job = candidate_obj.job_position_id
|
||||
cand_dep = cand_job.department_id
|
||||
cand_mail = candidate_obj.email
|
||||
cand_gender = candidate_obj.gender
|
||||
cand_company = candidate_obj.recruitment_id.company_id
|
||||
cand_documents = candidate_obj.candidatedocument_set.all()
|
||||
user_exists = User.objects.filter(username=cand_mail).exists()
|
||||
if user_exists:
|
||||
messages.error(request, _("Employee instance already exist"))
|
||||
elif not Employee.objects.filter(employee_user_id__username=can_mail).exists():
|
||||
elif not Employee.objects.filter(employee_user_id__username=cand_mail).exists():
|
||||
new_employee = Employee.objects.create(
|
||||
employee_first_name=can_name,
|
||||
email=can_mail,
|
||||
phone=can_mob,
|
||||
gender=can_gender,
|
||||
employee_first_name=cand_name,
|
||||
email=cand_mail,
|
||||
phone=cand_mob,
|
||||
gender=cand_gender,
|
||||
is_directly_converted=True,
|
||||
)
|
||||
candidate_obj.converted_employee_id = new_employee
|
||||
@@ -1689,11 +1691,25 @@ def candidate_conversion(request, cand_id, **kwargs):
|
||||
work_info, created = EmployeeWorkInformation.objects.get_or_create(
|
||||
employee_id=new_employee
|
||||
)
|
||||
work_info.job_position_id = can_job
|
||||
work_info.department_id = can_dep
|
||||
work_info.company_id = can_company
|
||||
work_info.job_position_id = cand_job
|
||||
work_info.department_id = cand_dep
|
||||
work_info.company_id = cand_company
|
||||
work_info.save()
|
||||
messages.success(request, _("Employee instance created successfully"))
|
||||
|
||||
emp_document_list = []
|
||||
for doc in cand_documents:
|
||||
emp_document = Document(
|
||||
title=doc.title,
|
||||
employee_id=new_employee,
|
||||
document=doc.document,
|
||||
status=doc.status,
|
||||
reject_reason=doc.reject_reason,
|
||||
)
|
||||
emp_document_list.append(emp_document)
|
||||
|
||||
if emp_document_list:
|
||||
print(emp_document_list)
|
||||
Document.objects.bulk_create(emp_document_list)
|
||||
else:
|
||||
messages.info(request, "A employee with this mail already exists")
|
||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))
|
||||
@@ -3258,6 +3274,7 @@ def document_create(request, id):
|
||||
"""
|
||||
candidate_id = Candidate.objects.get(id=id)
|
||||
form = CandidateDocumentForm(initial={"candidate_id": candidate_id})
|
||||
form.fields["candidate_id"].queryset = Candidate.objects.filter(id=id)
|
||||
if request.method == "POST":
|
||||
form = CandidateDocumentForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
@@ -3299,6 +3316,7 @@ def update_document_title(request, id):
|
||||
|
||||
@login_required
|
||||
@hx_request_required
|
||||
@manager_can_enter("candidate.add_candidate")
|
||||
def document_delete(request, id):
|
||||
"""
|
||||
Handle the deletion of a document, with permissions and error handling.
|
||||
@@ -3311,9 +3329,6 @@ def document_delete(request, id):
|
||||
"""
|
||||
try:
|
||||
document = CandidateDocument.objects.filter(id=id)
|
||||
# users can delete own documents
|
||||
if not request.user.has_perm("horilla_documents.delete_document"):
|
||||
document = document.filter(employee_id__employee_user_id=request.user)
|
||||
if document:
|
||||
document.delete()
|
||||
messages.success(
|
||||
@@ -3412,7 +3427,7 @@ def view_file(request, id):
|
||||
|
||||
@login_required
|
||||
@hx_request_required
|
||||
@manager_can_enter("horilla_documents.add_document")
|
||||
@manager_can_enter("candidate.add_candidate")
|
||||
def document_approve(request, id):
|
||||
"""
|
||||
This function used to view the approve uploaded document.
|
||||
@@ -3436,7 +3451,7 @@ def document_approve(request, id):
|
||||
|
||||
@login_required
|
||||
@hx_request_required
|
||||
@manager_can_enter("horilla_documents.add_document")
|
||||
@manager_can_enter("candidate.add_candidate")
|
||||
def document_reject(request, id):
|
||||
"""
|
||||
This function used to view the reject uploaded document.
|
||||
|
||||
Reference in New Issue
Block a user