mirror of
https://github.com/bringout/oca-ocb-hr.git
synced 2026-04-27 04:32:03 +02:00
19.0 vanilla
This commit is contained in:
parent
a1137a1456
commit
e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions
|
|
@ -3,4 +3,5 @@
|
|||
|
||||
from . import hr_job
|
||||
from . import hr_applicant
|
||||
from . import survey_invite
|
||||
from . import survey_survey
|
||||
from . import survey_user_input
|
||||
|
|
|
|||
|
|
@ -1,20 +1,35 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import timedelta
|
||||
from odoo import fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class Applicant(models.Model):
|
||||
class HrApplicant(models.Model):
|
||||
_inherit = "hr.applicant"
|
||||
|
||||
survey_id = fields.Many2one('survey.survey', related='job_id.survey_id', string="Survey", readonly=True)
|
||||
response_id = fields.Many2one('survey.user_input', "Response", ondelete="set null", copy=False)
|
||||
response_state = fields.Selection(related='response_id.state', readonly=True)
|
||||
response_ids = fields.One2many('survey.user_input', 'applicant_id', string="Responses")
|
||||
|
||||
def action_print_survey(self):
|
||||
""" If response is available then print this response otherwise print survey form (print template of the survey) """
|
||||
self.ensure_one()
|
||||
return self.survey_id.action_print_survey(answer=self.response_id)
|
||||
sorted_interviews = self.response_ids\
|
||||
.filtered(lambda i: i.survey_id == self.survey_id)\
|
||||
.sorted(lambda i: i.create_date, reverse=True)
|
||||
if not sorted_interviews:
|
||||
action = self.survey_id.action_print_survey()
|
||||
action['target'] = 'new'
|
||||
return action
|
||||
|
||||
answered_interviews = sorted_interviews.filtered(lambda i: i.state == 'done')
|
||||
if answered_interviews:
|
||||
action = self.survey_id.action_print_survey(answer=answered_interviews[0])
|
||||
action['target'] = 'new'
|
||||
return action
|
||||
action = self.survey_id.action_print_survey(answer=sorted_interviews[0])
|
||||
action['target'] = 'new'
|
||||
return action
|
||||
|
||||
def action_send_survey(self):
|
||||
self.ensure_one()
|
||||
|
|
@ -22,13 +37,31 @@ class Applicant(models.Model):
|
|||
# if an applicant does not already has associated partner_id create it
|
||||
if not self.partner_id:
|
||||
if not self.partner_name:
|
||||
raise UserError(_('You must define a Contact Name for this applicant.'))
|
||||
self.partner_id = self.env['res.partner'].create({
|
||||
raise UserError(_('Please provide an applicant name.'))
|
||||
self.partner_id = self.env['res.partner'].sudo().create({
|
||||
'is_company': False,
|
||||
'type': 'private',
|
||||
'name': self.partner_name,
|
||||
'email': self.email_from,
|
||||
'phone': self.partner_phone,
|
||||
'mobile': self.partner_mobile
|
||||
})
|
||||
return self.survey_id.with_context(default_applicant_id=self.id, default_partner_ids=self.partner_id.ids).action_send_survey()
|
||||
|
||||
self.survey_id.check_validity()
|
||||
template = self.env.ref('hr_recruitment_survey.mail_template_applicant_interview_invite', raise_if_not_found=False)
|
||||
local_context = dict(
|
||||
default_applicant_id=self.id,
|
||||
default_partner_ids=self.partner_id.ids,
|
||||
default_survey_id=self.survey_id.id,
|
||||
default_use_template=bool(template),
|
||||
default_template_id=template and template.id or False,
|
||||
default_email_layout_xmlid='mail.mail_notification_light',
|
||||
default_deadline=fields.Datetime.now() + timedelta(days=15)
|
||||
)
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _("Send an interview"),
|
||||
'view_mode': 'form',
|
||||
'res_model': 'survey.invite',
|
||||
'target': 'new',
|
||||
'context': local_context,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@
|
|||
from odoo import fields, models, _
|
||||
|
||||
|
||||
class Job(models.Model):
|
||||
class HrJob(models.Model):
|
||||
_inherit = "hr.job"
|
||||
|
||||
survey_id = fields.Many2one(
|
||||
'survey.survey', "Interview Form",
|
||||
'survey.survey', "Interview Form", index='btree_not_null',
|
||||
help="Choose an interview form for this job position and you will be able to print/answer this interview from all applicants who apply for this job")
|
||||
|
||||
def action_test_survey(self):
|
||||
|
|
@ -18,16 +18,15 @@ class Job(models.Model):
|
|||
def action_new_survey(self):
|
||||
self.ensure_one()
|
||||
survey = self.env['survey.survey'].create({
|
||||
'title': _("Interview Form : %s") % self.name,
|
||||
'title': _("Interview Form: %s", self.name),
|
||||
})
|
||||
self.write({'survey_id': survey.id})
|
||||
|
||||
action = {
|
||||
'name': _('Survey'),
|
||||
'view_mode': 'form,tree',
|
||||
'view_mode': 'form,list',
|
||||
'res_model': 'survey.survey',
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {'form_view_initial_mode': 'edit'},
|
||||
'res_id': survey.id,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.tools.misc import clean_context
|
||||
|
||||
|
||||
class SurveyInvite(models.TransientModel):
|
||||
_inherit = "survey.invite"
|
||||
|
||||
applicant_id = fields.Many2one('hr.applicant', string='Applicant')
|
||||
|
||||
def action_invite(self):
|
||||
self.ensure_one()
|
||||
if self.applicant_id:
|
||||
survey = self.survey_id.with_context(clean_context(self.env.context))
|
||||
|
||||
if not self.applicant_id.response_id:
|
||||
self.applicant_id.write({
|
||||
'response_id': survey._create_answer(partner=self.applicant_id.partner_id).id
|
||||
})
|
||||
|
||||
partner = self.applicant_id.partner_id
|
||||
survey_link = survey._get_html_link(title=survey.title)
|
||||
partner_link = partner._get_html_link()
|
||||
content = _('The survey %(survey_link)s has been sent to %(partner_link)s', survey_link=survey_link, partner_link=partner_link)
|
||||
body = '<p>%s</p>' % content
|
||||
self.applicant_id.message_post(body=body)
|
||||
return super().action_invite()
|
||||
|
||||
|
||||
class SurveyUserInput(models.Model):
|
||||
_inherit = "survey.user_input"
|
||||
|
||||
applicant_id = fields.One2many('hr.applicant', 'response_id', string='Applicant')
|
||||
|
||||
def _mark_done(self):
|
||||
odoobot = self.env.ref('base.partner_root')
|
||||
for user_input in self:
|
||||
if user_input.applicant_id:
|
||||
body = _('The applicant "%s" has finished the survey.', user_input.applicant_id.partner_name)
|
||||
user_input.applicant_id.message_post(body=body, author_id=odoobot.id)
|
||||
return super()._mark_done()
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, values_list):
|
||||
if 'default_applicant_id' in self.env.context:
|
||||
self = self.with_context(default_applicant_id=False)
|
||||
return super().create(values_list)
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SurveySurvey(models.Model):
|
||||
_inherit = 'survey.survey'
|
||||
|
||||
survey_type = fields.Selection(selection_add=[('recruitment', 'Recruitment')], ondelete={'recruitment': 'set default'})
|
||||
hr_job_ids = fields.One2many("hr.job", "survey_id", string="Job Position")
|
||||
|
||||
@api.depends('survey_type')
|
||||
@api.depends_context('uid')
|
||||
def _compute_allowed_survey_types(self):
|
||||
super()._compute_allowed_survey_types()
|
||||
if self.env.user.has_group('hr_recruitment.group_hr_recruitment_interviewer') or \
|
||||
self.env.user.has_group('survey.group_survey_user'):
|
||||
self.allowed_survey_types = (self.allowed_survey_types or []) + ['recruitment']
|
||||
|
||||
def get_formview_id(self, access_uid=None):
|
||||
if self.survey_type == 'recruitment':
|
||||
access_user = self.env['res.users'].browse(access_uid) if access_uid else self.env.user
|
||||
if not access_user.has_group('survey.group_survey_user'):
|
||||
if view := self.env.ref('hr_recruitment_survey.survey_survey_view_form', raise_if_not_found=False):
|
||||
return view.id
|
||||
return super().get_formview_id(access_uid=access_uid)
|
||||
|
||||
def action_survey_user_input_completed(self):
|
||||
action = super().action_survey_user_input_completed()
|
||||
if self.survey_type == 'recruitment':
|
||||
action.update({
|
||||
'domain': [('survey_id.survey_type', '=', 'recruitment')]
|
||||
})
|
||||
return action
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, _
|
||||
|
||||
|
||||
class SurveyUser_Input(models.Model):
|
||||
_inherit = "survey.user_input"
|
||||
|
||||
applicant_id = fields.Many2one('hr.applicant', string='Applicant', index='btree_not_null')
|
||||
|
||||
def _mark_done(self):
|
||||
odoobot = self.env.ref('base.partner_root')
|
||||
for user_input in self:
|
||||
if user_input.applicant_id:
|
||||
body = _('The applicant "%s" has finished the survey.', user_input.applicant_id.partner_name)
|
||||
user_input.applicant_id.message_post(body=body, author_id=odoobot.id)
|
||||
return super()._mark_done()
|
||||
Loading…
Add table
Add a link
Reference in a new issue