ATS ATTACHMENTS
This commit is contained in:
parent
9cb7d4ad44
commit
07aaf675be
|
|
@ -254,7 +254,7 @@ class HRApplicant(models.Model):
|
|||
'view_mode': 'form',
|
||||
'view_type': 'form',
|
||||
'target': 'new',
|
||||
'context': {'default_attachment_ids': []}
|
||||
'context': {'default_req_attachment_ids': []}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ class HRApplicant(models.Model):
|
|||
'view_mode': 'form',
|
||||
'view_type': 'form',
|
||||
'target': 'new',
|
||||
'context': {'default_attachment_ids': [],'default_is_pre_onboarding_attachment_request': True}
|
||||
'context': {'default_req_attachment_ids': [],'default_is_pre_onboarding_attachment_request': True}
|
||||
}
|
||||
def _track_template(self, changes):
|
||||
res = super(HRApplicant, self)._track_template(changes)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,20 @@
|
|||
from odoo import models, fields, api
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class PostOnboardingAttachmentWizard(models.TransientModel):
|
||||
_name = 'post.onboarding.attachment.wizard'
|
||||
_description = 'Post Onboarding Attachment Wizard'
|
||||
|
||||
attachment_ids = fields.Many2many(
|
||||
req_attachment_ids = fields.Many2many(
|
||||
'recruitment.attachments',
|
||||
string='Attachments to Request'
|
||||
)
|
||||
attachment_ids = fields.Many2many('ir.attachment')
|
||||
is_pre_onboarding_attachment_request = fields.Boolean(default=False)
|
||||
template_id = fields.Many2one('mail.template', string='Email Template',compute='_compute_template_id')
|
||||
submit_date = fields.Date(string='Submission Date', required=True, default=fields.Date.today())
|
||||
send_email_from_odoo = fields.Boolean(string="Send Email From Odoo", default=False)
|
||||
email_from = fields.Char('Email From')
|
||||
email_to = fields.Char('Email To')
|
||||
email_cc = fields.Text('Email CC')
|
||||
|
|
@ -18,56 +24,89 @@ class PostOnboardingAttachmentWizard(models.TransientModel):
|
|||
prefetch=True, translate=True, sanitize='email_outgoing',
|
||||
)
|
||||
|
||||
@api.depends('is_pre_onboarding_attachment_request')
|
||||
def _compute_template_id(self):
|
||||
for rec in self:
|
||||
if rec.is_pre_onboarding_attachment_request:
|
||||
rec.template_id = self.env.ref('hr_recruitment_extended.email_template_request_documents',
|
||||
raise_if_not_found=False)
|
||||
else:
|
||||
rec.template_id = self.env.ref('hr_recruitment_extended.email_template_post_onboarding_form',
|
||||
raise_if_not_found=False)
|
||||
|
||||
@api.onchange('template_id')
|
||||
def _onchange_template_id(self):
|
||||
""" Update the email body and recipients based on the selected template. """
|
||||
if self.template_id:
|
||||
record_id = self.env.context.get('active_id')
|
||||
applicant = self.env['hr.applicant'].browse(record_id)
|
||||
|
||||
if record_id:
|
||||
record = self.env[self.template_id.model].sudo().browse(record_id)
|
||||
|
||||
if not record.exists():
|
||||
raise UserError("The record does not exist or is not accessible.")
|
||||
|
||||
# Fetch email template
|
||||
email_template = self.env['mail.template'].sudo().browse(self.template_id.id)
|
||||
|
||||
if not email_template:
|
||||
raise UserError("Email template not found.")
|
||||
|
||||
self.email_from = self.env.company.email
|
||||
self.email_to = applicant.email_from
|
||||
self.email_body = email_template.body_html # Assign the rendered email bodyc
|
||||
self.email_subject = email_template.subject
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
"""Pre-fill attachments with is_default=True"""
|
||||
defaults = super(PostOnboardingAttachmentWizard, self).default_get(fields_list)
|
||||
default_attachments = self.env['recruitment.attachments'].search([('is_default', '=', True)])
|
||||
if default_attachments:
|
||||
defaults['attachment_ids'] = [(6, 0, default_attachments.ids)]
|
||||
defaults['req_attachment_ids'] = [(6, 0, default_attachments.ids)]
|
||||
return defaults
|
||||
|
||||
|
||||
def action_confirm(self):
|
||||
self.ensure_one()
|
||||
context = self.env.context
|
||||
active_id = context.get('active_id')
|
||||
applicant = self.env['hr.applicant'].browse(active_id)
|
||||
for rec in self:
|
||||
self.ensure_one()
|
||||
context = self.env.context
|
||||
active_id = context.get('active_id')
|
||||
applicant = self.env['hr.applicant'].browse(active_id)
|
||||
|
||||
applicant.recruitment_attachments = [(4, attachment.id) for attachment in self.attachment_ids]
|
||||
applicant.recruitment_attachments = [(4, attachment.id) for attachment in rec.req_attachment_ids]
|
||||
|
||||
template = rec.template_id
|
||||
|
||||
personal_docs = rec.req_attachment_ids.filtered(lambda a: a.attachment_type == 'personal').mapped('name')
|
||||
education_docs = rec.req_attachment_ids.filtered(lambda a: a.attachment_type == 'education').mapped('name')
|
||||
previous_employer_docs = rec.req_attachment_ids.filtered(
|
||||
lambda a: a.attachment_type == 'previous_employer').mapped('name')
|
||||
other_docs = rec.req_attachment_ids.filtered(lambda a: a.attachment_type == 'others').mapped('name')
|
||||
|
||||
|
||||
if self.is_pre_onboarding_attachment_request:
|
||||
template = self.env.ref('hr_recruitment_extended.email_template_request_documents', raise_if_not_found=False)
|
||||
else:
|
||||
template = self.env.ref('hr_recruitment_extended.email_template_post_onboarding_form', raise_if_not_found=False)
|
||||
# Prepare context for the template
|
||||
email_context = {
|
||||
'personal_docs': personal_docs,
|
||||
'education_docs': education_docs,
|
||||
'previous_employer_docs': previous_employer_docs,
|
||||
'other_docs': other_docs,
|
||||
}
|
||||
email_values = {
|
||||
'email_from': rec.email_from,
|
||||
'email_to': rec.email_to,
|
||||
'email_cc': rec.email_cc,
|
||||
'attachment_ids': [(6, 0, rec.attachment_ids.ids)],
|
||||
|
||||
}
|
||||
# Use 'with_context' to override the email template fields dynamically
|
||||
template.sudo().with_context(default_body_html=rec.email_body, default_subject=rec.email_subject,
|
||||
**email_context).send_mail(applicant.id, email_values=email_values,
|
||||
force_send=True)
|
||||
|
||||
|
||||
personal_docs = self.attachment_ids.filtered(lambda a: a.attachment_type == 'personal').mapped('name')
|
||||
education_docs = self.attachment_ids.filtered(lambda a: a.attachment_type == 'education').mapped('name')
|
||||
previous_employer_docs = self.attachment_ids.filtered(
|
||||
lambda a: a.attachment_type == 'previous_employer').mapped('name')
|
||||
other_docs = self.attachment_ids.filtered(lambda a: a.attachment_type == 'others').mapped('name')
|
||||
|
||||
|
||||
# Prepare context for the template
|
||||
email_context = {
|
||||
'personal_docs': personal_docs,
|
||||
'education_docs': education_docs,
|
||||
'previous_employer_docs': previous_employer_docs,
|
||||
'other_docs': other_docs,
|
||||
}
|
||||
|
||||
email_values = {
|
||||
'email_to': applicant.email_from,
|
||||
'auto_delete': True,
|
||||
}
|
||||
|
||||
template.with_context(**email_context).send_mail(
|
||||
applicant.id, force_send=True, email_values=email_values
|
||||
)
|
||||
|
||||
if self.is_pre_onboarding_attachment_request:
|
||||
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'
|
||||
|
|
|
|||
|
|
@ -1,19 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="view_post_onboarding_attachment_wizard_form" model="ir.ui.view">
|
||||
<field name="name">post.onboarding.attachment.wizard.form</field>
|
||||
<field name="model">post.onboarding.attachment.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Attachments">
|
||||
<group>
|
||||
<field name="attachment_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_confirm" type="object" string="Send Email" class="btn-primary"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<field name="name">post.onboarding.attachment.wizard.form</field>
|
||||
<field name="model">post.onboarding.attachment.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Select Attachments">
|
||||
<group>
|
||||
<field name="req_attachment_ids" widget="many2many_tags" force_save="1"/>
|
||||
<field name="is_pre_onboarding_attachment_request" readonly="1" force_save="1" invisible="1"/>
|
||||
</group>
|
||||
|
||||
<notebook>
|
||||
<page name="attachment" string="Attachments (Binary)">
|
||||
<field name="attachment_ids" widget="many2many_binary"
|
||||
domain="[('mimetype', 'not ilike', 'image')]"/>
|
||||
</page>
|
||||
<page name='email' string='Email'>
|
||||
<group>
|
||||
<field name="template_id" options="{'no_create': True}" readonly="1" force_save="1"/>
|
||||
<field name="email_from" placeholder="Comma-separated recipient addresses" force_save="1"/>
|
||||
<field name="email_to" force_save="1"/>
|
||||
<field name="email_cc" placeholder="Comma-separated carbon copy recipients addresses"/>
|
||||
<field name="email_subject" options="{'dynamic_placeholder': true}" placeholder="e.g. "Welcome to MyCompany" or "Nice to meet you, {{ object.name }}"" force_save="1"/>
|
||||
<field name="email_body" widget="html_mail" class="oe-bordered-editor"
|
||||
options="{'codeview': true, 'dynamic_placeholder': true}" force_save="1"/>
|
||||
|
||||
<!-- ✅ Show attachments as tags (preview) -->
|
||||
<field name="attachment_ids" widget="many2many_tags" string="Attachments" force_save="1"/>
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
|
||||
<footer>
|
||||
<button name="action_confirm" type="object" string="Send Email" class="btn-primary"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</odoo>
|
||||
Loading…
Reference in New Issue