commit
0788f34aa8
|
|
@ -2,16 +2,21 @@ from odoo import fields, api, models, _
|
|||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class HRApplicant(models.Model):
|
||||
_inherit = 'hr.applicant'
|
||||
|
||||
joining_form_link = fields.Char()
|
||||
|
||||
|
||||
class HREmployee(models.Model):
|
||||
_inherit = 'hr.employee'
|
||||
|
||||
|
||||
applicant_id = fields.Many2one("hr.applicant")
|
||||
|
||||
def send_jod_form_to_employee(self):
|
||||
for rec in self:
|
||||
if not rec.applicant_id:
|
||||
application = self.env['hr.applicant'].sudo().search([('employee_id','=',rec.id)],limit=1)
|
||||
application = self.env['hr.applicant'].sudo().search([('employee_id', '=', rec.id)], limit=1)
|
||||
if not application:
|
||||
candidate = self.env['hr.candidate'].sudo().create({
|
||||
'partner_name': rec.name,
|
||||
|
|
@ -30,11 +35,11 @@ class HREmployee(models.Model):
|
|||
return rec.sudo().applicant_id.send_post_onboarding_form_to_candidate()
|
||||
|
||||
|
||||
|
||||
|
||||
class PostOnboardingAttachmentWizard(models.TransientModel):
|
||||
_inherit = 'post.onboarding.attachment.wizard'
|
||||
|
||||
send_mail = fields.Boolean(default=False)
|
||||
|
||||
@api.onchange('template_id')
|
||||
def _onchange_template_id(self):
|
||||
""" Update the email body and recipients based on the selected template. """
|
||||
|
|
@ -65,7 +70,6 @@ class PostOnboardingAttachmentWizard(models.TransientModel):
|
|||
self.email_body = email_template.body_html # Assign the rendered email bodyc
|
||||
self.email_subject = email_template.subject
|
||||
|
||||
|
||||
def action_confirm(self):
|
||||
for rec in self:
|
||||
self.ensure_one()
|
||||
|
|
@ -89,7 +93,6 @@ class PostOnboardingAttachmentWizard(models.TransientModel):
|
|||
lambda a: a.attachment_type == 'previous_employer').mapped('name')
|
||||
other_docs = rec.req_attachment_ids.filtered(lambda a: a.attachment_type == 'others').mapped('name')
|
||||
|
||||
|
||||
# Prepare context for the template
|
||||
email_context = {
|
||||
'personal_docs': personal_docs,
|
||||
|
|
@ -106,14 +109,30 @@ class PostOnboardingAttachmentWizard(models.TransientModel):
|
|||
|
||||
}
|
||||
# Use 'with_context' to override the email template fields dynamically
|
||||
if rec.send_mail:
|
||||
template.sudo().with_context(default_body_html=rec.email_body,
|
||||
**email_context).send_mail(applicant.id, email_values=email_values,
|
||||
force_send=True)
|
||||
|
||||
base_url = self.get_base_url()
|
||||
|
||||
if rec.is_pre_onboarding_attachment_request:
|
||||
applicant.doc_requests_form_status = 'email_sent_to_candidate'
|
||||
else:
|
||||
applicant.post_onboarding_form_status = 'email_sent_to_candidate'
|
||||
applicant.joining_form_link = '%s/FTPROTECH/JoiningForm/%s'%(base_url,applicant.id)
|
||||
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
||||
def get_base_url(self):
|
||||
""" Return rooturl for a specific record.
|
||||
|
||||
By default, it returns the ir.config.parameter of base_url
|
||||
but it can be overridden by model.
|
||||
|
||||
:return: the base url for this record
|
||||
:rtype: str
|
||||
"""
|
||||
if len(self) > 1:
|
||||
raise ValueError("Expected singleton or no record: %s" % self)
|
||||
return self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
|
|
|
|||
|
|
@ -11,4 +11,34 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_post_onboarding_attachment_wizard_form_inherit" model="ir.ui.view">
|
||||
<field name="name">post.onboarding.attachment.wizard.form.inherit</field>
|
||||
<field name="model">post.onboarding.attachment.wizard</field>
|
||||
<field name="inherit_id" ref="hr_recruitment_extended.view_post_onboarding_attachment_wizard_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='req_attachment_ids']" position="after">
|
||||
<field name="send_mail"/>
|
||||
</xpath>
|
||||
<xpath expr="//notebook" position="attributes">
|
||||
<attribute name="invisible">not send_mail</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='action_confirm']" position="attributes">
|
||||
<attribute name="string">Send</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="hr_applicant_view_form_inherit_extend" model="ir.ui.view">
|
||||
<field name="name">hr.applicant.view.form.extend</field>
|
||||
<field name="model">hr.applicant</field>
|
||||
<field name="inherit_id" ref="hr_recruitment_extended.hr_applicant_view_form_inherit"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='post_onboarding_form_status']" position="after">
|
||||
<field name="joining_form_link" force_save="1" readonly="1"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue