diff --git a/addons_extensions/employee_jod/__init__.py b/addons_extensions/employee_jod/__init__.py new file mode 100644 index 000000000..9a7e03ede --- /dev/null +++ b/addons_extensions/employee_jod/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/addons_extensions/employee_jod/__manifest__.py b/addons_extensions/employee_jod/__manifest__.py new file mode 100644 index 000000000..75977ada3 --- /dev/null +++ b/addons_extensions/employee_jod/__manifest__.py @@ -0,0 +1,21 @@ +# __manifest__.py +{ + 'name': 'Employee JOD Form', + 'version': '1.0', + 'category': 'Human Resources', + 'summary': 'Send JOD form to employee after joining', + 'description': """ + This module is used to send the JOD (Joining Onboarding Document) form + to employees after they have joined the organization. + """, + 'author': 'FTPROTECH', + 'website': 'https://ftprotech.in', + 'depends': ['hr', 'mail','hr_employee_extended','hr_recruitment_extended'], + 'data': [ + 'data/data.xml', + 'data/actions.xml', + 'data/template.xml', + 'views/emp_jod.xml', + ], + 'license': 'LGPL-3', +} diff --git a/addons_extensions/employee_jod/controllers/__init__.py b/addons_extensions/employee_jod/controllers/__init__.py new file mode 100644 index 000000000..ec0561edd --- /dev/null +++ b/addons_extensions/employee_jod/controllers/__init__.py @@ -0,0 +1 @@ +from . import emp_jod_controller \ No newline at end of file diff --git a/addons_extensions/employee_jod/controllers/emp_jod_controller.py b/addons_extensions/employee_jod/controllers/emp_jod_controller.py new file mode 100644 index 000000000..e69de29bb diff --git a/addons_extensions/employee_jod/data/actions.xml b/addons_extensions/employee_jod/data/actions.xml new file mode 100644 index 000000000..853a0ce0a --- /dev/null +++ b/addons_extensions/employee_jod/data/actions.xml @@ -0,0 +1,27 @@ + + + + + Send JOD to EMPLOYEE + + + + form + code + action = records.send_jod_form_to_employee() + + + + Download Joining Form + hr.employee + qweb-pdf + employee_jod.emp_joining_form_template + employee_jod.emp_joining_form_template + + 'JOD - %s' % (object.display_name) + + report + + + + \ No newline at end of file diff --git a/addons_extensions/employee_jod/data/data.xml b/addons_extensions/employee_jod/data/data.xml new file mode 100644 index 000000000..a4461c7f5 --- /dev/null +++ b/addons_extensions/employee_jod/data/data.xml @@ -0,0 +1,26 @@ + + + + + + Internal Job + + + + + + IJ + + + + + + + + IJ001 + + + + + + \ No newline at end of file diff --git a/addons_extensions/employee_jod/data/template.xml b/addons_extensions/employee_jod/data/template.xml new file mode 100644 index 000000000..56e37cc38 --- /dev/null +++ b/addons_extensions/employee_jod/data/template.xml @@ -0,0 +1,316 @@ + + + + + \ No newline at end of file diff --git a/addons_extensions/employee_jod/models/__init__.py b/addons_extensions/employee_jod/models/__init__.py new file mode 100644 index 000000000..4fe43c877 --- /dev/null +++ b/addons_extensions/employee_jod/models/__init__.py @@ -0,0 +1 @@ +from . import emp_jod \ No newline at end of file diff --git a/addons_extensions/employee_jod/models/emp_jod.py b/addons_extensions/employee_jod/models/emp_jod.py new file mode 100644 index 000000000..11a22bcee --- /dev/null +++ b/addons_extensions/employee_jod/models/emp_jod.py @@ -0,0 +1,119 @@ +from odoo import fields, api, models, _ +from odoo.exceptions import UserError + + +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) + if not application: + candidate = self.env['hr.candidate'].sudo().create({ + 'partner_name': rec.name, + 'email_from': rec.work_email, + 'partner_phone': rec.work_phone, + 'employee_id': rec.id, + }) + + application = self.env['hr.applicant'].sudo().create({ + 'candidate_id': candidate.id, + 'hr_job_recruitment': self.env.ref('employee_jod.employee_jod_internal_job_recruitment_id').id, + 'recruitment_stage_id': self.env.ref('employee_jod.hired_stage8').id, + }) + rec.applicant_id = application.id + rec.sudo().applicant_id.send_post_onboarding_form = True + return rec.sudo().applicant_id.send_post_onboarding_form_to_candidate() + + + + +class PostOnboardingAttachmentWizard(models.TransientModel): + _inherit = 'post.onboarding.attachment.wizard' + + @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') + model = self.env.context.get('active_model') + + if model == 'hr.applicant': + applicant = self.env['hr.applicant'].browse(record_id) + else: + if model == 'hr.employee': + applicant = self.env['hr.employee'].browse(record_id).applicant_id + + if applicant: + record = self.env[self.template_id.model].sudo().browse(applicant.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 + + + def action_confirm(self): + for rec in self: + self.ensure_one() + context = self.env.context + active_id = context.get('active_id') + model = context.get('active_model') + + if model == 'hr.applicant': + applicant = self.env['hr.applicant'].browse(active_id) + else: + if model == 'hr.employee': + applicant = self.env['hr.employee'].browse(active_id).applicant_id + + 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') + + + # 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, + 'subject': rec.email_subject, + '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, + **email_context).send_mail(applicant.id, email_values=email_values, + force_send=True) + + + 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' + + return {'type': 'ir.actions.act_window_close'} diff --git a/addons_extensions/employee_jod/views/emp_jod.xml b/addons_extensions/employee_jod/views/emp_jod.xml new file mode 100644 index 000000000..35b71cd2f --- /dev/null +++ b/addons_extensions/employee_jod/views/emp_jod.xml @@ -0,0 +1,14 @@ + + + + hr.employee.view.form.applicant.id + hr.employee + + + + + + + + + \ No newline at end of file