From 5c76d3ddd27602fc836e4bb325f4dbf0d5cb0ad7 Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Fri, 9 Jun 2023 06:39:46 +0000 Subject: [PATCH] [FIX] website_hr_recruitment: prevent applying for unpublished job Issue: ------ When we have the link to the form to apply for a job, even if the job is not published, we can still apply. Solution: --------- Check that the job is published before the creation of the record in the `website_form_input_filter`. opw-3331717 closes odoo/odoo#125429 X-original-commit: d68eab464654441d51f618c5d3d036999316ed7f Signed-off-by: Kevin Baptiste Signed-off-by: Lefebvre Thomas (thle) --- .../website_hr_recruitment/i18n/website_hr_recruitment.pot | 7 +++++++ addons/website_hr_recruitment/models/hr_applicant.py | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/addons/website_hr_recruitment/i18n/website_hr_recruitment.pot b/addons/website_hr_recruitment/i18n/website_hr_recruitment.pot index 043dd935d88..651e4e8c1b1 100644 --- a/addons/website_hr_recruitment/i18n/website_hr_recruitment.pot +++ b/addons/website_hr_recruitment/i18n/website_hr_recruitment.pot @@ -766,6 +766,13 @@ msgid "" "displayed on the main Jobs' list page." msgstr "" +#. module: website_hr_recruitment +#. odoo-python +#: code:addons/website_hr_recruitment/models/hr_recruitment.py:0 +#, python-format +msgid "You cannot apply for this job." +msgstr "" + #. module: website_hr_recruitment #: model_terms:ir.ui.view,arch_db:website_hr_recruitment.thankyou_ir_ui_view msgid "Your contact information is:" diff --git a/addons/website_hr_recruitment/models/hr_applicant.py b/addons/website_hr_recruitment/models/hr_applicant.py index 99a4e968d63..4e1ed0641fc 100644 --- a/addons/website_hr_recruitment/models/hr_applicant.py +++ b/addons/website_hr_recruitment/models/hr_applicant.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import models, _ +from odoo.exceptions import UserError class Applicant(models.Model): @@ -14,6 +15,9 @@ class Applicant(models.Model): name = '%s - %s' % (values['partner_name'], applicant_job) if applicant_job else _("%s's Application", values['partner_name']) values.setdefault('name', name) if values.get('job_id'): + job = self.env['hr.job'].browse(values.get('job_id')) + if not job.sudo().website_published: + raise UserError(_("You cannot apply for this job.")) stage = self.env['hr.recruitment.stage'].sudo().search([ ('fold', '=', False), '|', ('job_ids', '=', False), ('job_ids', '=', values['job_id']),