ATS ATTACHMENTS

This commit is contained in:
karuna 2025-05-15 16:03:53 +05:30
parent 9cb7d4ad44
commit 07aaf675be
3 changed files with 115 additions and 52 deletions

View File

@ -254,7 +254,7 @@ class HRApplicant(models.Model):
'view_mode': 'form', 'view_mode': 'form',
'view_type': 'form', 'view_type': 'form',
'target': 'new', 'target': 'new',
'context': {'default_attachment_ids': []} 'context': {'default_req_attachment_ids': []}
} }
@ -266,7 +266,7 @@ class HRApplicant(models.Model):
'view_mode': 'form', 'view_mode': 'form',
'view_type': 'form', 'view_type': 'form',
'target': 'new', '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): def _track_template(self, changes):
res = super(HRApplicant, self)._track_template(changes) res = super(HRApplicant, self)._track_template(changes)

View File

@ -1,14 +1,20 @@
from odoo import models, fields, api from odoo import models, fields, api
from odoo.exceptions import UserError
class PostOnboardingAttachmentWizard(models.TransientModel): class PostOnboardingAttachmentWizard(models.TransientModel):
_name = 'post.onboarding.attachment.wizard' _name = 'post.onboarding.attachment.wizard'
_description = 'Post Onboarding Attachment Wizard' _description = 'Post Onboarding Attachment Wizard'
attachment_ids = fields.Many2many( req_attachment_ids = fields.Many2many(
'recruitment.attachments', 'recruitment.attachments',
string='Attachments to Request' string='Attachments to Request'
) )
attachment_ids = fields.Many2many('ir.attachment')
is_pre_onboarding_attachment_request = fields.Boolean(default=False) 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_from = fields.Char('Email From')
email_to = fields.Char('Email To') email_to = fields.Char('Email To')
email_cc = fields.Text('Email CC') email_cc = fields.Text('Email CC')
@ -18,36 +24,66 @@ class PostOnboardingAttachmentWizard(models.TransientModel):
prefetch=True, translate=True, sanitize='email_outgoing', 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 @api.model
def default_get(self, fields_list): def default_get(self, fields_list):
"""Pre-fill attachments with is_default=True""" """Pre-fill attachments with is_default=True"""
defaults = super(PostOnboardingAttachmentWizard, self).default_get(fields_list) defaults = super(PostOnboardingAttachmentWizard, self).default_get(fields_list)
default_attachments = self.env['recruitment.attachments'].search([('is_default', '=', True)]) default_attachments = self.env['recruitment.attachments'].search([('is_default', '=', True)])
if default_attachments: if default_attachments:
defaults['attachment_ids'] = [(6, 0, default_attachments.ids)] defaults['req_attachment_ids'] = [(6, 0, default_attachments.ids)]
return defaults return defaults
def action_confirm(self): def action_confirm(self):
for rec in self:
self.ensure_one() self.ensure_one()
context = self.env.context context = self.env.context
active_id = context.get('active_id') active_id = context.get('active_id')
applicant = self.env['hr.applicant'].browse(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
if self.is_pre_onboarding_attachment_request: personal_docs = rec.req_attachment_ids.filtered(lambda a: a.attachment_type == 'personal').mapped('name')
template = self.env.ref('hr_recruitment_extended.email_template_request_documents', raise_if_not_found=False) education_docs = rec.req_attachment_ids.filtered(lambda a: a.attachment_type == 'education').mapped('name')
else: previous_employer_docs = rec.req_attachment_ids.filtered(
template = self.env.ref('hr_recruitment_extended.email_template_post_onboarding_form', raise_if_not_found=False)
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') lambda a: a.attachment_type == 'previous_employer').mapped('name')
other_docs = self.attachment_ids.filtered(lambda a: a.attachment_type == 'others').mapped('name') other_docs = rec.req_attachment_ids.filtered(lambda a: a.attachment_type == 'others').mapped('name')
# Prepare context for the template # Prepare context for the template
@ -57,17 +93,20 @@ class PostOnboardingAttachmentWizard(models.TransientModel):
'previous_employer_docs': previous_employer_docs, 'previous_employer_docs': previous_employer_docs,
'other_docs': other_docs, 'other_docs': other_docs,
} }
email_values = { email_values = {
'email_to': applicant.email_from, 'email_from': rec.email_from,
'auto_delete': True, '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)
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' applicant.doc_requests_form_status = 'email_sent_to_candidate'
else: else:
applicant.post_onboarding_form_status = 'email_sent_to_candidate' applicant.post_onboarding_form_status = 'email_sent_to_candidate'

View File

@ -6,14 +6,38 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Select Attachments"> <form string="Select Attachments">
<group> <group>
<field name="attachment_ids" widget="many2many_tags"/> <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> </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. &quot;Welcome to MyCompany&quot; or &quot;Nice to meet you, {{ object.name }}&quot;" 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> <footer>
<button name="action_confirm" type="object" string="Send Email" class="btn-primary"/> <button name="action_confirm" type="object" string="Send Email" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/> <button string="Cancel" class="btn-secondary" special="cancel"/>
</footer> </footer>
</form> </form>
</field> </field>
</record> </record>
</odoo> </odoo>