From 08da110bdd398fc18f57842d019af0d5fadd8dc7 Mon Sep 17 00:00:00 2001 From: Pranay Date: Wed, 25 Jun 2025 11:12:01 +0530 Subject: [PATCH] optional mail send --- .../employee_jod/models/emp_jod.py | 39 ++++++++++++++----- .../employee_jod/views/emp_jod.xml | 30 ++++++++++++++ 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/addons_extensions/employee_jod/models/emp_jod.py b/addons_extensions/employee_jod/models/emp_jod.py index 11a22bcee..e1999837f 100644 --- a/addons_extensions/employee_jod/models/emp_jod.py +++ b/addons_extensions/employee_jod/models/emp_jod.py @@ -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 - 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.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') diff --git a/addons_extensions/employee_jod/views/emp_jod.xml b/addons_extensions/employee_jod/views/emp_jod.xml index 35b71cd2f..b8aa8eb6e 100644 --- a/addons_extensions/employee_jod/views/emp_jod.xml +++ b/addons_extensions/employee_jod/views/emp_jod.xml @@ -11,4 +11,34 @@ + + + post.onboarding.attachment.wizard.form.inherit + post.onboarding.attachment.wizard + + + + + + + not send_mail + + + Send + + + + + + + hr.applicant.view.form.extend + hr.applicant + + + + + + + + \ No newline at end of file