Skip to content
Snippets Groups Projects
Commit f23e07dc authored by William Braeckman's avatar William Braeckman
Browse files

[FIX] hr_recruitment: fix calendar_events


When using the Add button on the calendar view introduced with
odoo/odoo#64948 the event would not be linked with the applicant.

After further investigation the method used to get the applicant id in
default_get was not flexible enough, the one from crm calendar has been
'copied'

Task ID: 2578165

closes odoo/odoo#72731

Signed-off-by: default avatarYannick Tivisse (yti) <yti@odoo.com>
parent de629275
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ class CalendarEvent(models.Model):
def default_get(self, fields):
if self.env.context.get('default_applicant_id'):
self = self.with_context(
default_res_model='hr.applicant', #res_model seems to be lost without this
default_res_model_id=self.env.ref('hr_recruitment.model_hr_applicant').id,
default_res_id=self.env.context['default_applicant_id']
)
......@@ -19,9 +20,11 @@ class CalendarEvent(models.Model):
defaults = super(CalendarEvent, self).default_get(fields)
# sync res_model / res_id to opportunity id (aka creating meeting from lead chatter)
if 'applicant_id' not in defaults and defaults.get('res_id') and (defaults.get('res_model') or defaults.get('res_model_id')):
if (defaults.get('res_model') and defaults['res_model'] == 'hr.applicant') or (defaults.get('res_model_id') and self.env['ir.model'].sudo().browse(defaults['res_model_id']).model == 'hr.applicant'):
defaults['applicant_id'] = defaults['res_id']
if 'applicant_id' not in defaults:
res_model = defaults.get('res_model', False) or self.env.context.get('default_res_model')
res_model_id = defaults.get('res_model_id', False) or self.env.context.get('default_res_model_id')
if (res_model and res_model == 'hr.applicant') or (res_model_id and self.env['ir.model'].sudo().browse(res_model_id).model == 'hr.applicant'):
defaults['applicant_id'] = defaults.get('res_id', False) or self.env.context.get('default_res_id', False)
return defaults
......
......@@ -312,6 +312,7 @@ class Applicant(models.Model):
category = self.env.ref('hr_recruitment.categ_meet_interview')
res = self.env['ir.actions.act_window'].for_xml_id('calendar', 'action_calendar_event')
res['context'] = {
'default_applicant_id': self.id,
'default_partner_ids': partners.ids,
'default_user_id': self.env.uid,
'default_name': self.name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment