From 01c2146d1353582cd9c2821c3c7eac02ea25b9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 24 Jan 2023 15:48:29 +0000 Subject: [PATCH] [FIX] hr_recruitment_survey: protect against ill-formed default values 'survey.user_input' model has an inherit in hr_recruitment_survey module to link survey answers to applicants. The field is named 'applicant_id' which leads to issues with 'default_applicant_id' is present in context. This happens quite often when going from a kanban view notably, as it adds this filter in context when displaying applicants. Trying to send a recruitment survey to this applicant fails as it tries to set an ID in a o2m. In this commit we simply remove the default value in context to avoid issues. As anyway this model is technical it should not depend on default values. In master we will rename the field to avoid issues. Followup of odoo/odoo#63946 Task-3093257 (Mail: The Composer Update) closes odoo/odoo#110958 X-original-commit: e215ae152d0d2cad315d87ef03c58599f6d20e13 Signed-off-by: Kevin Baptiste Signed-off-by: Thibault Delavallee (tde) --- addons/hr_recruitment_survey/models/survey_invite.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/hr_recruitment_survey/models/survey_invite.py b/addons/hr_recruitment_survey/models/survey_invite.py index 8de974bac90..61d7b9a064d 100644 --- a/addons/hr_recruitment_survey/models/survey_invite.py +++ b/addons/hr_recruitment_survey/models/survey_invite.py @@ -1,6 +1,6 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models, _ +from odoo import api, fields, models, _ from odoo.tools.misc import clean_context @@ -40,3 +40,9 @@ class SurveyUserInput(models.Model): body = _('The applicant "%s" has finished the survey.', user_input.applicant_id.partner_name) user_input.applicant_id.message_post(body=body, author_id=odoobot.id) return super()._mark_done() + + @api.model_create_multi + def create(self, values_list): + if 'default_applicant_id' in self.env.context: + self = self.with_context(default_applicant_id=False) + return super().create(values_list)