[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 <kba@odoo.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Thibault Delavallée
2023-01-25 15:31:01 +01:00
parent 35224583f4
commit 01c2146d13
@@ -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)