feature/odoo18 #2
|
|
@ -335,59 +335,62 @@ class WebsiteJobHrRecruitment(WebsiteHrRecruitment):
|
|||
@http.route('/website_hr_recruitment_extended/check_recent_application', type='json', auth="public", website=True)
|
||||
def check_recent_application(self, value, job_id):
|
||||
# Function to check if the applicant has an existing record based on email, phone, or linkedin
|
||||
def refused_applicants_condition(applicant):
|
||||
return not applicant.active \
|
||||
and applicant.hr_job_recruitment.id == int(job_id) \
|
||||
and applicant.create_date >= (datetime.now() - relativedelta(months=6))
|
||||
# Search for applicants with the same email, phone, or linkedin (only if the value is not False/None)
|
||||
applicants_with_similar_info = http.request.env['hr.applicant'].sudo().search([
|
||||
('hr_job_recruitment','=',int(job_id)),
|
||||
'|',
|
||||
('email_normalized', '=', email_normalize(value)),
|
||||
'|',
|
||||
('partner_phone', '=', value),
|
||||
('linkedin_profile', '=ilike', value),
|
||||
], order='create_date DESC')
|
||||
if value:
|
||||
def refused_applicants_condition(applicant):
|
||||
return not applicant.active \
|
||||
and applicant.hr_job_recruitment.id == int(job_id) \
|
||||
and applicant.create_date >= (datetime.now() - relativedelta(months=6))
|
||||
# Search for applicants with the same email, phone, or linkedin (only if the value is not False/None)
|
||||
applicants_with_similar_info = http.request.env['hr.applicant'].sudo().search([
|
||||
('hr_job_recruitment','=',int(job_id)),
|
||||
'|',
|
||||
('email_normalized', '=', email_normalize(value)),
|
||||
'|',
|
||||
('partner_phone', '=', value),
|
||||
('linkedin_profile', '=ilike', value),
|
||||
], order='create_date DESC')
|
||||
|
||||
if not applicants_with_similar_info:
|
||||
return {'message':None}
|
||||
# Group applications by their status
|
||||
applications_by_status = applicants_with_similar_info.grouped('application_status')
|
||||
if not applicants_with_similar_info:
|
||||
return {'message':None}
|
||||
# Group applications by their status
|
||||
applications_by_status = applicants_with_similar_info.grouped('application_status')
|
||||
|
||||
# Check for refused applicants with the same value within the last 6 months
|
||||
refused_applicants = applications_by_status.get('refused', http.request.env['hr.applicant'])
|
||||
if any(applicant for applicant in refused_applicants if refused_applicants_condition(applicant)):
|
||||
return {
|
||||
'message': _(
|
||||
'We\'ve found a previous closed application in our system within the last 6 months.'
|
||||
' Please consider before applying in order not to duplicate efforts.'
|
||||
)
|
||||
}
|
||||
|
||||
# Check for ongoing applications with the same value
|
||||
ongoing_applications = applications_by_status.get('ongoing', [])
|
||||
if ongoing_applications:
|
||||
ongoing_application = ongoing_applications[0]
|
||||
if ongoing_application.hr_job_recruitment.id == int(job_id):
|
||||
recruiter_contact = "" if not ongoing_application.user_id else _(
|
||||
' In case of issue, contact %(contact_infos)s',
|
||||
contact_infos=", ".join(
|
||||
[value for value in itemgetter('name', 'email', 'phone')(ongoing_application.user_id) if value]
|
||||
))
|
||||
|
||||
error_message = 'An application already exists for %s Duplicates might be rejected. %s '%(value,recruiter_contact)
|
||||
print(error_message)
|
||||
# Check for refused applicants with the same value within the last 6 months
|
||||
refused_applicants = applications_by_status.get('refused', http.request.env['hr.applicant'])
|
||||
if any(applicant for applicant in refused_applicants if refused_applicants_condition(applicant)):
|
||||
return {
|
||||
'message': _(error_message)
|
||||
'message': _(
|
||||
'We\'ve found a previous closed application in our system within the last 6 months.'
|
||||
' Please consider before applying in order not to duplicate efforts.'
|
||||
)
|
||||
}
|
||||
|
||||
# If no existing application found, show the following message
|
||||
return {
|
||||
'message': _(
|
||||
'We found a recent application with a similar name, email, phone number.'
|
||||
' You can continue if it\'s not a mistake.'
|
||||
)
|
||||
}
|
||||
# Check for ongoing applications with the same value
|
||||
ongoing_applications = applications_by_status.get('ongoing', [])
|
||||
if ongoing_applications:
|
||||
ongoing_application = ongoing_applications[0]
|
||||
if ongoing_application.hr_job_recruitment.id == int(job_id):
|
||||
recruiter_contact = "" if not ongoing_application.user_id else _(
|
||||
' In case of issue, contact %(contact_infos)s',
|
||||
contact_infos=", ".join(
|
||||
[value for value in itemgetter('name', 'email', 'phone')(ongoing_application.user_id) if value]
|
||||
))
|
||||
|
||||
error_message = 'An application already exists for %s Duplicates might be rejected. %s '%(value,recruiter_contact)
|
||||
print(error_message)
|
||||
return {
|
||||
'message': _(error_message)
|
||||
}
|
||||
|
||||
# If no existing application found, show the following message
|
||||
return {
|
||||
'message': _(
|
||||
'We found a recent application with a similar name, email, phone number.'
|
||||
' You can continue if it\'s not a mistake.'
|
||||
)
|
||||
}
|
||||
else:
|
||||
return {'message': None}
|
||||
|
||||
def _should_log_authenticate_message(self, record):
|
||||
if record._name == "hr.applicant" and not request.session.uid:
|
||||
|
|
@ -395,7 +398,6 @@ class WebsiteJobHrRecruitment(WebsiteHrRecruitment):
|
|||
return super()._should_log_authenticate_message(record)
|
||||
|
||||
def extract_data(self, model, values):
|
||||
|
||||
candidate = False
|
||||
extracted_resume = values.pop('resume_base64', None)
|
||||
current_ctc = values.pop('current_ctc', None)
|
||||
|
|
@ -422,6 +424,21 @@ class WebsiteJobHrRecruitment(WebsiteHrRecruitment):
|
|||
total_experience = int(experience_years)
|
||||
total_experience_type = 'year'
|
||||
|
||||
if extracted_resume:
|
||||
attachment = request.env.ref("hr_recruitment_extended.employee_recruitment_attachments_preview")
|
||||
file = attachment.sudo().write({
|
||||
'datas': extracted_resume,
|
||||
})
|
||||
if file:
|
||||
resume_type = attachment.mimetype
|
||||
resume_name = attachment.name
|
||||
else:
|
||||
resume_type = ''
|
||||
resume_name = ''
|
||||
else:
|
||||
resume_type = ''
|
||||
resume_name = ''
|
||||
|
||||
skill_dict = {key: ast.literal_eval(value) for key,value in values.items() if "skill" in key and value != '0'}
|
||||
|
||||
if model.model == 'hr.applicant':
|
||||
|
|
@ -435,6 +452,7 @@ class WebsiteJobHrRecruitment(WebsiteHrRecruitment):
|
|||
'|', ('email_from', '=', partner_email),
|
||||
('partner_phone', '=', partner_phone),
|
||||
], limit=1)
|
||||
|
||||
if candidate:
|
||||
candidate.sudo().write({
|
||||
'partner_name': partner_name,
|
||||
|
|
@ -442,7 +460,9 @@ class WebsiteJobHrRecruitment(WebsiteHrRecruitment):
|
|||
'email_from': partner_email,
|
||||
'partner_phone': partner_phone,
|
||||
'type_id': int(degree) if degree.isdigit() else False,
|
||||
'resume': extracted_resume
|
||||
'resume': extracted_resume,
|
||||
'resume_type': resume_type,
|
||||
'resume_name': resume_name,
|
||||
})
|
||||
if not candidate:
|
||||
candidate = request.env['hr.candidate'].sudo().create({
|
||||
|
|
@ -451,7 +471,9 @@ class WebsiteJobHrRecruitment(WebsiteHrRecruitment):
|
|||
'partner_phone': partner_phone,
|
||||
'alternate_phone': alternate_phone,
|
||||
'type_id': int(degree) if degree.isdigit() else False,
|
||||
'resume': extracted_resume
|
||||
'resume': extracted_resume,
|
||||
'resume_type': resume_type,
|
||||
'resume_name': resume_name,
|
||||
})
|
||||
|
||||
if len(skill_dict) > 0:
|
||||
|
|
@ -466,8 +488,9 @@ class WebsiteJobHrRecruitment(WebsiteHrRecruitment):
|
|||
candidate_skills['skill_type_id'] = skill_type_id
|
||||
# skill = request.env['hr.candidate.skill'].sudo().create(candidate_skills)
|
||||
# candidate_skills_list.append(skill.id)
|
||||
if candidate.candidate_skill_ids and candidate_skills['skill_id'] not in candidate.candidate_skill_ids.skill_id.ids:
|
||||
candidate.write({'candidate_skill_ids':[(0,4,candidate_skills)]})
|
||||
if candidate.candidate_skill_ids:
|
||||
if candidate_skills['skill_id'] not in candidate.candidate_skill_ids.skill_id.ids:
|
||||
candidate.write({'candidate_skill_ids':[(0,4,candidate_skills)]})
|
||||
else:
|
||||
candidate.write({'candidate_skill_ids':[(0,4,candidate_skills)]})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue